这是一个很长的回复......但我觉得它为一些提高网站性能的基本方法提供了足够的细节。
以下答案也适用于几乎任何网站。
下面提供的任何具体示例都可能适用于当前版本的http://www.jj-triggs.com/
在以下几点中,我指的是在 Firefox 中使用 Firebug 插件的 Net Panel,但在其他浏览器中使用
也有类似的工具,方法与我提到的几乎相同。
在 Firefox 上安装 Firebug 并打开您的网站。
为您的站点启用 Firebug (F12)。
如果尚未启用 Firebug 的 Net 面板,请启用它。
您的网站:http://www.jj-triggs.com/
- 在我的系统上重复访问需要 5-6 秒(对于这个答案,我没有提到改进的方法)
- 但第一次访问大约需要 60 秒。 (以下几点着重于如何改进)
下面提到的大多数要点都会在首次加载(或重新加载)时改善您的网站
已经加载页面后,要测试新加载,您可以使用 Ctrl+F5、Ctrl+R、Ctrl+Shift+R(取决于浏览器)。
页面加载时监控 Firebug 的 Net Panel。
一个网站需要多少时间取决于:
- The speed of the site host server (seems OK, nothing much to do for now)
- Visitor's connection speed (cannot do anything for it)
- Everything else (where you need to fix many things).
The important approaches to resolve them are listed below:
- Serve the user files with less size but same content:
- Approach:
Enable gzip on files which contain text contents (*.js, *.css, *.html etc) (currently your site does not use gzip)
- How to identify:
In Net panel, expand the HTTP request details for a file, in the Headers tab of the expanded details, Content-Encoding field should show the value gzip.
- Solution:
It might need you to modify .htaccess file (or some other approach based on the server)
Search on Google or StackOverflow to see how to enable it.
- Approach:
Use minified JS and CSS files
- How to identify:
In Net panel, expand the HTTP request details for a JS/CSS file, in the Response tab of the expanded details, the code should be a minified version (no whitespace characters) of the file.
- Solution:
Use either the minified JS/CSS files as provided by the library.
Or you can minify them yourself by using tools like "JSMin" or "YUI (CSS and JS) Compressor"
- Approach:
- Serve the user optimum images, i.e., less size with good enough quality
- How to identify:
- In Net Panel, go to Images tab > Sort by size
- Generally the size of the images should be ... 1kb to 30kb for simple icons and logos and 20kb to 250kb for photos and large backgrounds.
- Solution:
- Compress the large images with softwares like GIMP (free) or Photoshop.
- Approach:
- Load the files from a CDN if possible
- eg: Load jQuery, jQuery UI etc from popular but still free CDN
- Advantage even for first visit: If the user has visited any other site which refers to the same path, it would be fetched from the cache itself
- How to identify:
- Check the Net panel's "Domain" column for popular libraries like jQuery, jQuery UI etc.
They should be getting loaded from a popular CDN such as Google.
- Solution:
- Include JS and CSS from (Google) CDN if available.
- Approach:
- Load CSS before JS
- It may not necessarily help much with faster loading completion,
but it usually gives a faster feeling of load because your CSS gets applied as soon as possible.
- How to identify:
- Check the Timeline column in Net panel. Usually CSS files should be the getting loaded before JS.
- Solution:
- Move the <script> tags towards the bottom of the page.
- Approach:
- Wherever possible, load third-party components like Google Maps dynamically after the page load has completed
- How to identify:
- Check the Timeline column in Net panel. The 3rd-party components should usually begin loading after almost all the other code for the site has loaded.
- Solution:
- The solution would depend on the third-party component and might be a bit tricky.
Generally, loading the 3rd-party JavaScript after a small delay (using window.setTimeout and code to dynamically add script tags) would provide you better performance compared to loading the 3rd-party JS using plain HTML.
我相信解决这些提到的问题可能会将您的 (http://www.jj-triggs.com/) 首次加载时间减少到当前所需时间的 10-30%。