简体   繁体   中英

importing javascript library once

I'm building a website which imports a javascript library (located inside <head> ):

<script type="text/javascript" src="@routes.Assets.at("nicedit/nicEdit.js")"></script>

which means,
every page loading (no matter which page in my website), this line exists.

I wanted to know if modern browsers download the library once, and then cache it,
or every page load - the javascript is library re-downloaded.

thanks

Under normal circumstances most browsers will cache a javascript file if it is repeatedly requested from the same url; however, my definition of normal circumstances is wrapped up in how servers are usually set up. The real result depends on what cache headers the server is sending, as well as whether or not the URL changes (which is not clear from your question).

There are lots of questions on StackOverflow about caching JavaScript. This one includes something of a compendium.

Please try configuring http.cacheControl

http.cacheControl

HTTP Response headers control for static files: sets the default max-age in seconds, telling the user's browser how long it should cache the page. This is only read in prod mode, in dev mode the cache is disabled. For example, to send no-cache:

http.cacheControl=0 Default: 3600 - set cache expiry to one hour.

Source of the information.

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