About fallback for CDN

Asked

Viewed 157 times

8

Some people recommend using the following technique (fallback) to load Javascript libraries locally if the CDN is out of order:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="jquery.js"><\/script>')</script>

My question is: If the CDN is really off the air, the browser will not take several seconds to consider timeout and upload the local version? This would slow down the navigation as every page change it would try again.

1 answer

5


In most types of downtime, yes, will slow down the page, but at least it will work.

If the downtime is the type that responds quickly to unavailability, for example an internal error, this will be quickly resolved.

When there is downtime of google servers, it is very common to see services like buying airline tickets crashing, so your fallback is well valid, as measure to contain damage.

  • 1

    Besides, the big bet when using CDN is that the file already exists in cache in the browser, so downtime may not even be noticed.

  • 1

    the 2nd script can point to another CDN tbm <script>window.jQuery || document.write('<script src="//outro.cdn.com/jquery.js"><\/script>')</script>

Browser other questions tagged

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