开发者

Should I only be loading Javascript files on pages I need them?

开发者 https://www.devze.com 2023-01-29 06:15 出处:网络
So I am starting t开发者_JAVA技巧o get interested in Optimization and I was wondering if it is worth it to only include the Javascript files in the pages I need and exclude them from the rest using PH

So I am starting t开发者_JAVA技巧o get interested in Optimization and I was wondering if it is worth it to only include the Javascript files in the pages I need and exclude them from the rest using PHP?

Thanks


Loading only the scripts you need will definitely help.

Another huge improvement can be made by combining all javascript to one file and (if possible) minimizing and caching the output. The less requests a browser has to make, the faster your page will load.


Ideally, yes.

Each page should not load more than it needs. Minimising traffic is always good.

It is a good idea to have a framework for generating pages, and only add the resources you need for each page.


If you include all or most of the JavaScript that your site needs on your main page (in an minimized and compressed form like what is provided by YUI Compressor) it will increase the load time of your main page but will decrease the load time of every other page because the JavaScript will already be in cache. A lot of web applications will use this technique so that the user experience after the initial load is smoother.

Either technique has its merits, it really just depends on the type of application/page you are building. But like dirkbonhomme said you should be minimizing, compressing, and caching the JavaScript (and CSS) no matter which way you go.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号