arielsalminen / feature.js

Feature.js is a fast, simple and lightweight browser feature detection library in 1kb.
https://featurejs.com/
3.17k stars 115 forks source link

Use Object instead function constructor #10

Closed amovah closed 8 years ago

shshaw commented 8 years ago

Looks like your minification didn't compress variable names, making the feature.min.js file larger than the original, despite having less code! Might want to use Closure Compiler or another minifier that will rename variables to get that file size down.

I'd also suggest giving a slight version number bump to make the changes more apparent.

For example:

/*! FEATURE.JS 1.0.1, http://featurejs.com */
(function(b,c,h){var d=c.documentElement,a={create:function(f){return c.createElement(f)},old:!!/(Android\s(1.|2.))|(Silk\/1.)/i.test(navigator.userAgent),pfx:function(){var f=c.createElement("dummy").style,b=["Webkit","Moz","O","ms"],a={};return function(c){if("undefined"===typeof a[c]){var e=c.charAt(0).toUpperCase()+c.substr(1),e=(c+" "+b.join(e+" ")+e).split(" ");a[c]=null;for(var d in e)if(f[e[d]]!==h){a[c]=e[d];break}}return a[c]}}()},k=!(a.old||null===a.pfx("perspective")),l=!(a.old||null===
a.pfx("transformOrigin")),m=null!==a.pfx("transition"),n=!!b.addEventListener,p=!!c.querySelectorAll,q=!!b.matchMedia,r="placeholder"in a.create("input"),g;try{localStorage.setItem("x","x"),localStorage.removeItem("x"),g=!0}catch(f){g=!1}a={css3Dtransform:k,cssTransform:l,cssTransition:m,addEventListener:n,querySelectorAll:p,matchMedia:q,deviceMotion:"DeviceMotionEvent"in b,deviceOrientation:"DeviceOrientationEvent"in b,contextMenu:"contextMenu"in d&&"HTMLMenuItemElement"in b,classList:"classList"in
d,placeholder:r,localStorage:g,historyAPI:b.history&&"pushState"in b.history,serviceWorker:"serviceWorker"in navigator,viewportUnit:function(a){try{return a.style.width="1vw",""!==a.style.width}catch(b){return!1}}(a.create("dummy")),remUnit:function(a){try{return a.style.width="1rem",""!==a.style.width}catch(b){return!1}}(a.create("dummy")),canvas:function(a){return!(!a.getContext||!a.getContext("2d"))}(a.create("canvas")),svg:!!c.createElementNS&&!!c.createElementNS("http://www.w3.org/2000/svg",
"svg").createSVGRect,webGL:function(a){try{return!(!b.WebGLRenderingContext||!a.getContext("webgl")&&!a.getContext("experimental-webgl"))}catch(c){return!1}}(a.create("canvas")),cors:"XMLHttpRequest"in b&&"withCredentials"in new XMLHttpRequest,touch:!!("ontouchstart"in b||b.navigator&&b.navigator.msPointerEnabled&&b.MSGesture||b.DocumentTouch&&c instanceof DocumentTouch),async:"async"in a.create("script"),defer:"defer"in a.create("script"),geolocation:"geolocation"in navigator,srcset:"srcset"in a.create("img"),
sizes:"sizes"in a.create("img"),pictureElement:"HTMLPictureElement"in b,testAll:function(){var a=" js",b;for(b in this)"testAll"!==b&&"constructor"!==b&&this[b]&&(a+=" "+b);d.className+=a.toLowerCase()}};b.feature=a})(window,document);
amovah commented 8 years ago

@shshaw Good point, I fixed.

arielsalminen commented 8 years ago

@amovah Thanks for this, I'll merge this as soon possible. Currently in the middle of dozen things as just moved to a new country!

arielsalminen commented 8 years ago

Merged!