gulp-cdnfailover
gulp-cdnfailover is a gulp plugin to create HTML snippets that will try to load your JS/CSS sources from CDN locations and if there are any errors, it fails over to local sources. The HTML snippets for javascript are synchronous/blocking where as the CSS snippet will make its best effort to load the local files as quickly as possible.
Features
- Failover HTML snippet: Creates failover HTML snippet for both JS and CSS
- Integrity and crossOrigin: Both of these attributes are supported.
- Replaces placeholders in HTML file: And outputs the file where the snippets are placed.
Usage
Install gulp-cdnfailover
as a development dependency:
npm install --save-dev gulp-cdnfailover
Add it to your gulpfile.js
:
var cdnfailover = ; gulp ;
The module looks for <!-- cdnfailover:NAME_OF_ENTRY -->
line and replaces with the appropriate snippet. It automatically detects if it is a JS or a CSS resource by checking the extension of the local.
For the example above, your src/index.html should have these lines: <!-- cdnfailover:bootstrap-min-css -->
and <!-- cdnfailover:jquery-slim-min-js -->
Example:
<!-- cdnfailover:bootstrap-min-css --> <!-- Placed at the end of the document so the pages load faster --> <!-- cdnfailover:jquery-slim-min-js -->
The output will look like this:
<!-- Placed at the end of the document so the pages load faster -->
Options
verbose
Type: Boolean
If true
, log verbose while running.
uselocalfilesonly
Type: Boolean
If true
, we don't do any of these tricks in this extension. We simply output a