简体   繁体   中英

Is there a Performance/Security Penalty Including Unused Javascript or JQuery Calls on a Web Page

We are developing a master dynamic web template for our users. There are certain pages that may require calls to jquery-1.11.3.min.js for some functionality. The question came up about including it in the master page so it is available on every page if needed. I am curious if there is a performance or security penalty for doing this.

It's considered a bad practice to include files that are unused. Even though they might be cached, they still take up memory. If they are not cached then extra connection and trips are made over the wire and slow down your page.

I would recommend to use RequireJS for all your javascript dependency resolution

The first time it is requested, there may be a hit.

However, because jQuery is used widely, the chances are that it will be cached at some point along the server request chain, and quite possibly in the user's browers anyway. It's also minified, so the size is quite small.

That said, even if not cached, once it's been requested once, it will be cached in the users browser (almost certainly).

Here are some interesting questions / articles for further reading / info: Yahoo is well known for contributing to general knowledge on speeding up websites - read about this here: http://developer.yahoo.com/performance/rules.html

Google's equivalent: https://developers.google.com/speed/docs/insights/rules

The best answer here is really an opinion: your opinion .

This kind of thing is not necessarily bad practice; however, it can cause your website to slow down if the viewer has not cached the particular version of jQuery that you are using.

The answer to your question is another question: are you willing to make that sacrifice in order to be lazy and not include the link in every page that requires jQuery?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM