GithubHelp home page GithubHelp logo

willstocks / dynamically-polyfill-features-for-a-script Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 130 KB

A small, lightweight script to check for native browser feature support - only polyfill when necessary, no wasted requests on browsers that have native support! πŸ˜†πŸ€“

Home Page: https://willstocks.co.uk

License: MIT License

JavaScript 100.00%
cdn conditional contributions-welcome dynamic javascript open-source open-source-project polyfill polyfill-loader

dynamically-polyfill-features-for-a-script's People

Contributors

willstocks avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

mwong365

dynamically-polyfill-features-for-a-script's Issues

[Review] Optimal performance & supportability

I'm going to keep this issue open for a while, just until the repo has settled a bit. Any performance-related improvements, pop a comment down below and I will add them to this list.

Current areas for improvement:

[Enhancement] Code Cognitive Complexity

I am using the following branch

  • master
  • develop

Does this enhancement relate to an existing pull request

  • Yes
  • No
    If yes, PR: #

Describe the enhancement you'd like to see implemented

Resolve issues relating to cognitive complexity. See https://codeclimate.com/github/willstocks-tech/dynamically-polyfill-features-for-a-script/issues?category=complexity&engine_name%5B%5D=structure&engine_name%5B%5D=duplication

What are the benefits of implementation?

Code readability/supportability and overall complexity.

If applicable, describe any alternative solutions you've considered

Additional context

See: https://codeclimate.com/github/willstocks-tech/dynamically-polyfill-features-for-a-script/issues?category=complexity&engine_name%5B%5D=structure&engine_name%5B%5D=duplication - only file we're concerned about is the "core" dynamicpolyfill.js file - ignore any errors relating to -withinlinecomments.js

Have you worked on this yourself already? If so, link to your PR.

[Bug] Multiple polyfill.io requests rather than just one

Branch being used

  • master
  • develop

Describe the issue

Individual requests are being made to polyfill.io, instead of all features being bundled into a single request

Troubleshooting steps taken

To Reproduce
Steps to reproduce the behavior:

  1. Run script with all native features
  2. Monitor network waterfall
  3. See polyfill.io being called 3 times, when ['IntersectionObserver', 'IntersectionObserverEntry', 'Testing'] is being passed as the first parameter

Expected behavior

Only one request should be made to polyfill.io, with all features within that single request.

Screenshots

Desktop (please complete the following information):

  • OS:
  • Browser:
  • Version:

Smartphone (please complete the following information):

  • Device:
  • Mobile OS:
  • Browser:
  • Version:

Additional Information
Add any other context about the problem here.

[Feature Request] Allow array of scripts to load

Some people (sensible people) might want to load an array of external scripts. Rather than request the polyfill features separately (resulting in multiple requests), allow the passing of the array of polyfill features (already exists) PLUS an array of scripts so that all polyfills can be requested at once, rather than all separately

[Bug] Polyfill.io is still being called when no polyfill required

Branch being used

  • master
  • develop

Describe the issue

As of v0.0.5 polyfill.io is still being called, even when there's nothing to polyfill

Troubleshooting steps taken

To Reproduce
Steps to reproduce the behavior:

  1. Run script with all native features
  2. Monitor network waterfall
  3. See polyfill.io being called with no features requested

Expected behavior

Don't call polyfill.io if we don't need to - the whole point of this is to not waste requests

Screenshots

N/A

Desktop (please complete the following information):

  • OS: Windows 10, macOS
  • Browser: Chrome, Safari
  • Version: v72, latest stable macOS Safari

Smartphone (please complete the following information):

  • Device:
  • Mobile OS:
  • Browser:
  • Version:

Additional Information

[Bug] Uglifying JS breaks... everything!

Branch being used

  • master
  • develop

Describe the issue

Using .min.js results in a fair few errors + the script not actually executing (and potentially breaking other scripts on a site!)

Troubleshooting steps taken

Using non-minified, everything works fine. It looks like the uglification process changes things so much that things just aren't happy!
Trying to minify using different methods.

To Reproduce
Steps to reproduce the behavior:

  1. Copy the min.js file
  2. Paste it into a project/page
  3. Save and then reload a page that was known to work
  4. View console, see errors

Expected behavior

Shouldn't break anything. Should run in exactly the same manner as the non-minified version!

Screenshots

Desktop (please complete the following information):

  • OS:
  • Browser:
  • Version:

Smartphone (please complete the following information):

  • Device:
  • Mobile OS:
  • Browser:
  • Version:

Additional Information
Add any other context about the problem here.

[Bug] Chrome not executing init functions

For some reason, in Chrome, init functions aren't executing. The code is validating and the function is parsing, but the actual function never executes...

Something to do with:

try {
	window[fn]
}

Which was implemented due to Safari being weird with new Function

Converting back to:

try {
	var run = new Function(fn);
	run();
}

and stuff works.

Two options here...:

  1. Make window[fn] work some how
  2. Implement both methods in the same try... which feels wrong!

I refuse to use eval() based on SO/Google/very widespread opinion!

[Enhancement] Reliant on promises... which aren't fully supported in browsers that need polyfills (IE)

Polyfill promises before polyfilling the polyfills?

POLYFILL-CEPTION.

The polyfills we need to load are currently based on promises, which has fairly wide support (https://caniuse.com/#search=promise), except for IE11 and older versions of IE. Chances are, these are the browsers we'll want to be polyfilling functionality for, but can't because promises aren't supported.

Find a way to polyfill promises before running everything else... and without promise.then()

Whole script needs to be a bit more "dynamic"

Rather than statically declaring variables, what about passing them through as a function. That way this little script could be loaded off a CDN and variables passed through to it? Would also allow "per page polyfilling" to work a lot easier, with a lot less maintenance?

checkPolyfills( [featuresArray], scriptURL ) or something like that?

[Enhancement] Create a version of the script with inline comments

I am using the following branch

  • master
  • develop

Does this enhancement relate to an existing pull request

  • Yes
  • No

If yes, note PR number here: #19

Describe the enhancement you'd like to see implemented

Add a version of the script with inline comments.

What are the benefits of implementation?

New users/contributors will be able to better understand what each step of the script is doing and why.

If applicable, describe any alternative solutions you've considered

N/A

Additional context

N/A

Have you worked on this yourself already? If so, link to your PR.

#19
See: dynamicpolyfill-withinlinecomments.js

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.