date-input-polyfill icon indicating copy to clipboard operation
date-input-polyfill copied to clipboard

stop polyfill initialising if there are no date inputs on the page or…

Open pixelthing opened this issue 8 years ago • 2 comments

Hi @jcgertig - Loving this polyfill, but noticed that it initialises itself (including dependencies) even if there aren't any input:date on the page, or even if the browser supports it's own datepicker that overrides the polyfill. So this fixes that (if you like it) - it can save maybe 50ms on a modern PC, but can save a lot more on slower phones that would never use it anyway (most versions of android/iOS support native pickers).

Attached are flamecharts of how the existing version looks in Chrome 58 (which supports datepicker and overrides the polyfill anyway), how it looks when it detects browsers that support datepickers, and how it looks when there aren't any date inputs on the page. (ignore the time to load localhost HTML, webpack server is a bit inconsistent with load times!).

Hope it's ok to submit a PR!

date-input-polyfill-currently date-input-polyfill-new-date-supporting-browsers date-input-polyfill-date-notpresent-on-page

pixelthing avatar Apr 24 '17 13:04 pixelthing

I like the concept but this needs to be optional as not to break backwards compatibility. It loading by default helps sites that are dynamic and build dynamic forms. My suggestion is a data-attribute on the body tag such as data-date-input-conditional-load to decide if it loads by default or not.

Also don't commit changes to the .dist file I will commit that after doing a push to npm.

jcgertig avatar Apr 24 '17 13:04 jcgertig

understood about the commit to the dist - I'll work in the optional characteristics. Thanks!

pixelthing avatar May 04 '17 20:05 pixelthing