-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update stats and deployment instructions
"Local" and CDN deployment now included!
- Loading branch information
1 parent
a09343f
commit a873dab
Showing
1 changed file
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
A little script that allows you to only polyfill a feature when absolutely necessary - no wasted requests on browsers that have native support! 😆🤓 | ||
|
||
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: | ||
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: | ||
|
||
## Getting Started | ||
|
||
|
@@ -22,7 +22,18 @@ Make sure you know what features your script is reliant on and polyfill those no | |
|
||
## Deployment | ||
|
||
### Loading from CDN: | ||
### Loading locally (recommended): | ||
1. Copy the contents of [dynamicpolyfill.js](https://github.com/willstocks-tech/dynamically-polyfill-features-for-a-script/blob/master/dynamicpolyfill.js) | ||
1. Paste it into your existing JS file(s) | ||
1. Add a new line after it and call `dynamicPolyfill();` _Note: Case-sensitive_ | ||
1. Example: `dynamicPolyfill( ["IntersectionObserver", "Object.assign"], 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();')` | ||
2. Add an `onLoad` attribute to the tag calling the `dynamicPolyfill()` function and passing your parameters | ||
1. Note: the first parameter is the feature polyfills you want to pass. This is expected as an array. | ||
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. | ||
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` . | ||
1. Note: the 4th parameter has now been deprecated. | ||
|
||
### Loading from CDN (less recommended): | ||
1. Add a `<script></script>` tag linking to this script | ||
1. Example: `<script src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js'></script>` | ||
2. Add an `onLoad` attribute to the tag calling the `dynamicPolyfill()` function and passing your parameters | ||
|
@@ -31,8 +42,25 @@ Make sure you know what features your script is reliant on and polyfill those no | |
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` . | ||
1. Note: the 4th parameter has now been deprecated. | ||
|
||
#### CDN example script tag | ||
##### String variables: | ||
Note: Loading from a CDN would still result in a potentially wasted request :disappointed: | ||
|
||
#### Example method of usage | ||
|
||
##### Local | ||
|
||
###### String variables | ||
|
||
`dynamicPolyfill( 'IntersectionObserver', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();');` | ||
|
||
##### Array variables | ||
|
||
`dynamicPolyfill( ["IntersectionObserver", "Object.assign"], ['https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'https://other.cdn.net/script.js'], ['quicklink();', 'otherFunction();'] );` | ||
|
||
##### CDN | ||
|
||
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. | ||
|
||
###### String variables: | ||
``` | ||
<script | ||
src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js' | ||
|
@@ -44,15 +72,13 @@ Make sure you know what features your script is reliant on and polyfill those no | |
``` | ||
<script | ||
src='https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.min.js' | ||
onload='dynamicPolyfill( ["IntersectionObserver", "Object.assign"], ['https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'https://other.cdn.net/script.js'], ['quicklink();', 'otherFunction();'] )'> | ||
onload='dynamicPolyfill(["IntersectionObserver", "Object.assign"], ['https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'https://other.cdn.net/script.js'], ['quicklink();', 'otherFunction();'])'> | ||
</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! An example of this would be: `dynamicPolyfill(["IntersectionObserver", "Object.assign"], 'https://cdn.jsdelivr.net/npm/[email protected]/dist/quicklink.umd.js', 'quicklink();');`. | ||
|
||
## Built With | ||
|
||
* Vanilla Javascript - no framework dependencies! | ||
* Vanilla Javascript - no framework dependencies whatsoever! | ||
* [Polyfill.io](https://github.com/Financial-Times/polyfill-library) - for the actual polyfills! | ||
|
||
## Versioning | ||
|