-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES5 shim cleanup #3677
ES5 shim cleanup #3677
Conversation
We don''t support Blackberry and we should remove the shim. I think were also using it for Android 4.x as well. You can't tell me this works on Blackberry because no here can test it. |
I've been lazy about the iphone update, so still have BB7. We could remove the shim, deploy, and I could report back what happens in prod and then we can decide if we care. That work? |
No, we should drop support for it because we don't support it. I am seeing near 50 BB7 users since July 1, 2017. The only concern I have is the Android 4.x users. |
You give a convincing argument! Okay, I've re-worked it to use modernizr to check for es5 features (aside from strict mode—to handle IE9) and if they are absent, disable JS as we do in IE8. I checked in SauceLabs Android 4.4 (lowest I think they have) and ES5 features were supported. Also, contains #3678 |
@@ -165,25 +165,28 @@ | |||
{# Customized Modernizr build that includes html5shiv. | |||
Built via gulp-modernizer in `scripts.js` task. #} | |||
<script src="{{ static('js/modernizr.min.js') }}"></script> | |||
|
|||
{# | |||
Turn off JavaScript for browsers that don't support ECMAScript 5 features |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change the footer script to do the same instead of relying on the IE 8 comment hack? https://github.com/cfpb/cfgov-refresh/pull/3677/files#diff-89b43ee86bbd4952dc44cf751cfd775cR247
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay check now
@sebworks Per Jimmy's feedback to change the check in the footer to match, I wrapped the footer scripts in an if statement looking for the |
|
How do you feel about moving it to the header and making the load async to speed it up for JS users without blocking page load but also avoid loading any scripts for no JS users? |
cfgov/jinja2/v1/_layouts/base.html
Outdated
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c; | ||
})(window,document.documentElement,'optimize-loading','dataLayer',5000, | ||
{'GTM-KHB8MB':true}); | ||
(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this indentation change intentional? HTML files should still be four space, even if writing JS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was intentional. Once you're inside <script>
it's JS land, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. If we linted it, the linter would only care that the file was html, not what the code written inside of it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I reverted it, but I think a smart HTML linter wouldn't be touching what's inside a <script>
tag because it's not HTML. If we used something like https://www.npmjs.com/package/eslint-plugin-html#htmlindent, we could control it however we want, but it would still be JS and JS code style I'd think.
cfgov/jinja2/v1/_layouts/base.html
Outdated
available. Check for that CSS class here and act accordingly. | ||
#} | ||
<script> | ||
function loadScript(t,e){var n=document.createElement('script');n.type='text/javascript',n.onload=function(){return e?e():null},n.src=t,document.getElementsByTagName('head')[0].appendChild(n)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the unminified script:
function loadScript( url, callback ) {
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.onload = function() {
if ( callback ) {
return callback();
}
return null;
};
script.src = url;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually removed the callback onload bit, as none of the scripts use a callback. 25cf9ad
Builds fine and looks good in my IE8 VM. |
Thanks for fixing Travis @sebworks ! |
The ES5 shim/sham script was checking ES5 support twice in modernizer. Once in the base template and once in the es5-shim module. IE8 shouldn't need the shim because we turn off JS in IE8 (though in theory GTM could be using ES5 features, but if that happens the GTM script should be refactored to not use ES5 features, as they shouldn't require the amount of complexity that needs ES5 features). IE9 supports ES5 features except for strict-mode, which es5-shim does not polyfill anyway, so we don't need to deliver the shim there. IE10+ support es5 features, so shim doesn't need delivery there.
Update: Completely removes es5-shim.
Changes
RenamesscriptsEs5Shim
build functionscriptsES5Shim
to match ECMAScript case.common.ie.js
tocommon.ie9.js
to better convey that that is the only IE this module is delivered to.common.ie9.js
, since that's the only place it was used.Renameses5-shim.js
toes5-shim-sham.js
to better convey what it contains.Completely turn off delivery of es5-shim to conditional comment supporting IE versions.Removes redundant es5 feature check inside es5 shim module.fnBind
polyfill, since it is only needed for IE8 and BB7.IE8 shouldn't need the polyfill because the JS where it's used is turned off. BB7 should fail the modernizr es5 check and use the bind polyfill inside the es5 shim.Removes
Testing
gulp build
should pass.Notes
Todos
At some point if we want to drop BB7 es5 feature support we could remove es5-shim completely. @ascott1 @cfarm ?Dropping it!