gpt4 book ai didi

php - css 和 JS 文件下载时间过长

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:35:04 27 4
gpt4 key购买 nike

我在 linux 服务器上有一个用 cakephp 编写的网站。我的 css 和 js 文件下载速度极慢。例如,这是加载我的主页时 chrome 中的网络选项卡:

enter image description here

如您所见,我的一个 css 文件下载了 59 秒!重要的是要注意它并不总是相同的 css 文件。有时是它的 JS 文件,有时是其他 css,但它们必须在页面的其他内容显示之前下载,因此它们会阻止页面加载。由于等待那个文件下载,网站有 59 秒没有显示。

我检查了我的服务器,它的负载非常低,CPU 运行在 10% 上,并且使用的 ram 不到 20%。它是一个具有以下 prefork 设置的 apache 服务器:

StartServers       10
MinSpareServers 10
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 10000

这个提到的缓慢下载时间发生在网站上可能同时有 3-4 个用户时。我的应用程序在带有 appdynamics 的 APM 下,那里没有显示任何可疑内容。我用服务器管理员检查了 php.ini 文件,那里的一切似乎都很好。我可以使用哪些其他软件来查找此问题的根源? apache 日志中也没有太多信息。

如有任何建议,我们将不胜感激

编辑:

我将所有 Assets 移至 webroot,并在使用同一服务器的另一个域上获得了这些结果:

enter image description here

如您所见,这次它的 jquery 文件下载了 27 秒。它存储在 app/webroot

最佳答案

Ill take a look at serving assets from webroot

始终将公共(public) Assets 放在 webroot 中。

From the book (强调):

It’s a well known fact that serving assets through PHP is guaranteed to be slower than serving those assets without invoking PHP. And while the core team has taken steps to make plugin and theme asset serving as fast as possible, there may be situations where more performance is required. In these situations it’s recommended that you either symlink or copy out plugin/theme assets to directories in app/webroot with paths matching those used by CakePHP.

  • app/Plugin/DebugKit/webroot/js/my_file.js becomes app/webroot/debug_kit/js/my_file.js
  • app/View/Themed/Navy/webroot/css/navy.css becomes app/webroot/theme/Navy/css/navy.css

根据许多因素,“较慢”可能介于几乎不明显和几乎不可用之间。

此建议不是特定于版本的,并且几乎始终适用。为了加快 Assets 加载速度,让网络服务器为您处理它们。

关于php - css 和 JS 文件下载时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32717415/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com