changer
changer

Reputation: 409

Force download from local cache in Google Chrome

How can I force Google Chrome to download some .js/.css/images from local cache if remote file is not available (like if Chrome is configured to use Squid proxy, which will serve this file for me, even if cdn is not available).

For example, I load http://example.com which uses jquery library, located in CDN with address http://cdn-example.com/js/jquery.latest.js

Suddenly cdn-example.com becomes unavailable/respondes very slowly/respondes with 404 error/etc.

http://example.com is still available but is unusable because jquery is not loaded.

Upvotes: 2

Views: 1470

Answers (1)

drew010
drew010

Reputation: 69967

Is this actually happening? The point of a CDN is that it should be highly redundant and always available. If one host in the cluster goes down, your request will be routed to another that can serve the request.

I don't know of any possible way to do what you're asking, but if you're really concerned about it you can try something like this:

<html>
<head>
...
<script src="//cdn.com/js/jquery.latest.js"></script>
<script>window.jQuery || document.write('<script src="//otherplace.com/js/jquery.js"></script>')</script>

...
</head>

That tries to load it from the first URL, if that failed for one reason or another, the next script block checks to see if jQuery is defined (which it won't be on failure) and if so writes a new script tag to the document which triggers it to load from the fallback resource.

Upvotes: 1

Related Questions