GithubHelp home page GithubHelp logo

[Enhancement] Reliant on promises... which aren't fully supported in browsers that need polyfills (IE) about dynamically-polyfill-features-for-a-script HOT 6 CLOSED

willstocks avatar willstocks commented on May 29, 2024
[Enhancement] Reliant on promises... which aren't fully supported in browsers that need polyfills (IE)

from dynamically-polyfill-features-for-a-script.

Comments (6)

willstocks avatar willstocks commented on May 29, 2024

There's a way to do this for non-CDN usage... if the script is being self-hosted, the below can be used AFTER the inclusion of the dynamic polyfill script:

<script src="https://alink.to/promisepolyfill.js" onload="dynamicPolyfill([featuresarray], 'scripttouseURL', 'scriptfunctiontouse()', false)"></script>

Alternative (for CDN usage):

<script src="https://this.isalink.to/a/promisepolyfill.js"></script>
<script defer="defer" src="https://cdn.jsdelivr.net/gh/willstocks-tech/dynamically-polyfill-features-for-a-script@master/dynamicpolyfill.js" onload="dynamicPolyfill(['array', 'of.features', 'required'], 'scripttouseURL', 'scriptfunctiontouseafterpolyfillandload()', false)"></script>

from dynamically-polyfill-features-for-a-script.

willstocks avatar willstocks commented on May 29, 2024

callback function??? Or the following dirty approach?

function dynamicPolyfill (features, scriptURL, initFunction) {
	var polyfillFeatures = features;
	var scriptToPolyfill = scriptURL;
	var functionToRunonLoad = initFunction;
	if(typeof Promise !== "undefined") {
		return pageLoaded(polyfillFeatures, scriptToPolyfill, functionToRunonLoad);
	} else {
		console.warn("Promises not supported. Loading polyfill.");
		var promPol = document.createElement('script');
		promPol.src = ('https://polyfill.io/v3/polyfill.min.js?features=Promise');
		document.body.appendChild(promPol);
		polyfill.onerror = function(response) {
			console.error("Could not load Promise polyfill", response);
		} 
		polyfill.onload = function() {
			return pageLoaded(polyfillFeatures, scriptToPolyfill, functionToRunonLoad);
		}
	}
}

from dynamically-polyfill-features-for-a-script.

willstocks avatar willstocks commented on May 29, 2024

@MilesZew mentioned in PR #15 (comment):

I am currently working on a promise polyfill incase you were planning on working on it.

Once confirmed, this issue will be assigned to him

from dynamically-polyfill-features-for-a-script.

MilesZew avatar MilesZew commented on May 29, 2024

Here is the unfinished file (for the Promise polyfill)
Polyfill.zip

from dynamically-polyfill-features-for-a-script.

willstocks avatar willstocks commented on May 29, 2024

Had a thought - rather than include an inline polyfill for promises, why not just check for native support first (I’m on mobile, so this is syntactically incorrect!):

if(Promise) { //check if natively supported
checkPolyfill(p1, p2, p3)
} else {
promifill(p1, p2, p3)
}

function promifill(p1, p2, p3) {
//polyfill promise here using polyfill.io
promifillScript.onload = function(p1, p2, p3) {
checkPolyfill(p1, p2, p3)
}

from dynamically-polyfill-features-for-a-script.

willstocks avatar willstocks commented on May 29, 2024

Changing milestone to v0.0.6 as this has now been catered for in PR #19

from dynamically-polyfill-features-for-a-script.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.