Are libraries downloaded multiple times?

Asked

Viewed 189 times

12

I have an application that uses 3 libraries (Bootstrap, jQuery, jQueryUI) on 10 different pages. Browsers cache libraries?

2 answers

15


If they are coming from the same URL and there is no indication/setting otherwise is to cache within certain policies set by browsers/users.

To use what is cached a read attempt is made and must return 304 Not modified.

Exactly why it is recommended to use a default location where already exist these libraries. So yours website do not need to download what is already in the user’s browser. Even if it was originally downloaded by another website.

Usually comes out "cheaper" to load a full library of CDN from Google or of own library or any another place than making a custom version of it just with what you use.

Tutorial on cache.

12

In general, browsers do cache. Eventually they check for changes and download the file again, but most of the time you don’t have to worry so much about the performance.

If you want to change the default behavior, you can force this on your system or your browser by changing the HTTP headers Expires and Cache-Control. That’s more than enough for an intranet.

On the Internet you can use a link to a CDN repository, which contains the most common libraries. This way you save bandwidth and leverage the cache that may have been made in accessing other websites.

In the case of jQuery, for example, you can use the Cdns provided on own library website.

It is important to note that, unlike known libraries, caching specific scripts can be a problem if you make small changes over time. It is common for users to complain about bugs that appear soon after updating the system version, and the solution is usually to clear the cache.

To avoid this, one of the techniques used is to add a version number as a URL parameter when including the specific script. Example:

<script type="text/javascript" src="app-script.js?ver=1.1">

Updating the version along with the new ones releases system you will force the browser to download the new versions of scripts.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.