分享

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

 印度阿三17 2019-05-19

我有一个在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个同时用户.我在AppM下使用appdynamics我的应用程序,没有任何可疑的显示在那里.我用服务器管理员检查了php.ini文件,一切似乎都很好.我可以使用哪些其他软件来查找此问题的来源? apache日志中的信息也不多.

任何建议将不胜感激

编辑:

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

enter image description here

正如您所看到的,这次它的jquery文件需要27秒才能下载.它存储在app / webroot中

解决方法:

Ill take a look at serving assets from webroot

始终将公共资产放在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

根据许多因素,“较慢”可以介于几乎不可察觉到几乎无法使用的任何地方.

此建议不是特定于版本的,并且几乎总是适用.为了加快资产加载速度,让网络服务器为您处理这些问题.

来源:http://www./content-1-197951.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多