Optimizing javascript and css requests

后端 未结 11 1855
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 17:21

I need to optimize the loading speed of several existing websites. One of the issues that I have is the amount of requests per page. The websites have 7 or more different ty

11条回答
  •  [愿得一人]
    2020-12-31 17:52

    I think it's necessary to perform the following optimisations:

    • Server-side:

      1. Use fast web-server like nginx or lighttpd for serving js and css files if not using yet.
      2. Enable caching and gziping for the files.
    • And client-side:

      1. Place all common js-files into minified one and enable hardcore caching. If your page don't require running them before "onload", you can add one to page dynamically. It will speed up loading.
      2. Place per-page code into separate files and if it's not necessary to do smth. before onload event, add it dynamically.
      3. If it more than a few Kbytes of css at all, just merge it into one. Else you should split it to common and per-page styles.
      4. If you need best performance on client-side, place into common css file really common styles, that applied to ALL pages. Load rules you need on the page only, it will speed up rendering.
      5. The simplest way to minify js and css together is to use YUI Compress. If you want better speedup, you can remove all evals and other "dynamic" code and use Google Closure Compiler.

    If it will not help, than everything's bad and you need more servers to serve js and css files.

提交回复
热议问题