Optimizing javascript and css requests

后端 未结 11 1868
佛祖请我去吃肉
佛祖请我去吃肉 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:31

    Like some others have said, put used-on-more-than-one-page scripts all together into a main.js and then if there are page specific ones: home.js, another_page.js, etc.

    The only thing I really wanted to add was that for libraries like jQuery, you should use something like Google's Libraries API.

    • If your user has visited a different site which also uses Google's servers for the libraries, then they'll arrive with a primed cache! Win!
    • I'm going to go out on a limb here and bet that Google's servers are faster than yours.
    • Because the requests are going to different servers, clients can simultaneously process two requests to the Google servers (eg: jQuery & jQuery UI) as well as two requests to your servers (main.js & main.css)

    Oh, and finally -- don't forget to turn gzipping on your server!

提交回复
热议问题