You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@
10
10
11
11
A little script that allows you to only polyfill a feature when absolutely necessary - no wasted requests on browsers that have native support! 😆🤓
12
12
13
-
This script is ~3.51KB**un**minified _(1.29KB**un**minified and gzipped)_ or ~1.8KB minified _(891B minified and gzipped)_, so it's _fairly_ light. :smile:
13
+
This script is ~2.64KB**un**minified _(1KB**un**minified and gzipped)_ or ~1.55KB minified _(762B minified and gzipped)_, so it's _fairly_ light. :smile:
14
14
15
15
## Getting Started
16
16
@@ -23,28 +23,29 @@ Make sure you know what features your script is reliant on and polyfill those no
23
23
## Deployment
24
24
25
25
### Loading from CDN:
26
-
1. Add a <script></script> tag linking to this script
26
+
1. Add a `<script></script>` tag linking to this script
2. Add an `onLoad` attribute to the tag calling the `dynamicPolyfill()` function and passing your parameters
29
29
1. Note: the first parameter is the feature polyfills you want to pass. This is expected as an array.
30
-
1. Note: the second paramter is the URL of the script you want to use. This is expected as a string.
30
+
1. Note: the second paramter is the URL of the script you want to use. This is expected as a string, but can be blank (`''`) or `null` if you're not loading a third party script.
31
31
1. Note: the third parameter is the function that you would run once the script has loaded. This is expected as a string.
32
-
1. Note: the 4th parameter is a `true`/`false` flag. If using a CDN you need to set the flag to `false`.
32
+
1. Note: the 4th parameter has now been deprecated.
Note: You need to ensure that before you call the `dynamicPolyfill()` function that the actual script itself has loaded. If you're going to host the script yourself (rather than calling out to a CDN), make sure you include the script code first, then call the function. You can do this in the same manner as above, but replace the CDN URL with the path to your own JS file!
43
+
Note: You need to ensure that before you call the `dynamicPolyfill()` function that the actual script itself has loaded. If you're going to host the script yourself (rather than calling out to a CDN), make sure you include the script code first, then call the function. You can do this in the same manner as above, but replace the CDN URL with the path to your own JS file! An example of this would be: `dynamicPolyfill(["IntersectionObserver", "Object.assign"], 'https://cdn.jsdelivr.net/npm/quicklink@1.0.0/dist/quicklink.umd.js', 'quicklink();');`.
44
44
45
45
## Built With
46
46
47
47
* Vanilla Javascript - no framework dependencies!
48
+
*[Polyfill.io](https://github.com/Financial-Times/polyfill-library) - for the actual polyfills!
48
49
49
50
## Versioning
50
51
@@ -67,4 +68,5 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md
67
68
## Acknowledgments
68
69
69
70
*[PurpleBooth](https://gist.github.com/PurpleBooth) for this awesome README template!
71
+
*[Polyfill.io](https://github.com/Financial-Times/polyfill-library) for the awesome polyfill service!
//This file includes a bunch of console.log()/console.error()/console.warn() messages. Aides with troubleshooting, but is also a little fun if someone happens to come across them. They're not necessary at all tho'!
console.log("As the script is ready, let's initialise it...");
16
+
initialiseMyScript(functionToRunonLoad)
17
+
).catch(function(error){returnerror})
18
+
}
19
+
).catch(function(error){returnerror})
20
+
,function(){
21
+
console.error("There was an issue polyfilling",mayneedpolyfill," which means that I can't preload future pages for you. Sorry! :(");
22
+
console.warn("If you want this to work, I'd recommend upgrading to a browser that supports",mayneedpolyfill,"natively. You can find out which browsers do by visting: https://caniuse.com/");
23
+
}
24
+
}
25
+
26
+
functioncheckNativeSupport(tocheck){
27
+
varnum=tocheck.length;//cache value out of the for loop
0 commit comments