Friday, 16 September 2022

Local fallback for jquery.js, bootstrap.css and bootstrap.js incase CDNs are down or locall internet is not working

I need to provide a local fallback if the CDNs are down for jquery.js, bootstrap.css and bootstrap.js.

With jQuery I can do

<script src="https://code.jquery.com/jquery-3.6.1.min.js"  integrity="" crossorigin=""></script>
<script>window.jQuery || document.write('<script src="scripts/libraries/jquery-3.6.1.min.js"><\/script>')</script>

With bootstrap.css I can do using onerror

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" onerror="this.onerror=null;this.href='frameworks/bootstrap.min.css';" integrity="" crossorigin="" />

But when it comes to bootstrap.js the following does not work while I am using the same code as the above jQuery

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js" integrity="" crossorigin=""></script>
<script>window.jQuery || document.write('<script src="frameworks/bootstrap.bundle.min.js"><\/script>')</script>


from Local fallback for jquery.js, bootstrap.css and bootstrap.js incase CDNs are down or locall internet is not working

No comments:

Post a Comment