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
+34-8Lines changed: 34 additions & 8 deletions
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 ~4.76KB**un**minified (with comments!) _(1.52KB**un**minified and gzipped)_ or ~1.15KB minified _(520B minified and gzipped)_, so it's _fairly_ light. :smile:
13
+
This script is ~2.54KB**un**minified (104 lines) _(841B**un**minified and gzipped)_ or ~1.3KB minified (1 line) _(565B minified and gzipped)_, so it's _fairly_ light. :smile:
14
14
15
15
## Getting Started
16
16
@@ -22,7 +22,18 @@ Make sure you know what features your script is reliant on and polyfill those no
22
22
23
23
## Deployment
24
24
25
-
### Loading from CDN:
25
+
### Loading locally (recommended):
26
+
1. Copy the contents of [dynamicpolyfill.js](https://github.com/willstocks-tech/dynamically-polyfill-features-for-a-script/blob/master/dynamicpolyfill.js)
27
+
1. Paste it into your existing JS file(s)
28
+
1. Add a new line after it and call `dynamicPolyfill();`_Note: Case-sensitive_
2. Add an `onLoad` attribute to the tag calling the `dynamicPolyfill()` function and passing your parameters
31
+
1. Note: the first parameter is the feature polyfills you want to pass. This is expected as an array.
32
+
1. Note: the second paramter is the URL of the script you want to use. This is expected as a either a `string` or an `array`, but can be blank (`''`) or `null` if you're not loading a third party script.
33
+
1. Note: the third parameter is the function that you would run once the script has loaded. This is expected as a `string` or an `array` .
34
+
1. Note: the 4th parameter has now been deprecated.
35
+
36
+
### Loading from CDN (less recommended):
26
37
1. Add a `<script></script>` tag linking to this script
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, if you're not going to call it from the same file.
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/[email protected]/dist/quicklink.umd.js', 'quicklink();');`.
52
-
53
79
## Built With
54
80
55
-
* Vanilla Javascript - no framework dependencies!
81
+
* Vanilla Javascript - no framework dependencies whatsoever!
56
82
*[Polyfill.io](https://github.com/Financial-Times/polyfill-library) - for the actual polyfills!
0 commit comments