Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active August 29, 2015 14:01
Show Gist options
  • Save markhowellsmead/fd3f0d3fd3d872b76637 to your computer and use it in GitHub Desktop.
Save markhowellsmead/fd3f0d3fd3d872b76637 to your computer and use it in GitHub Desktop.
Load advanced Javascript if the browser understands modern terms{}
/*
From http://responsivenews.co.uk/post/18948466399/cutting-the-mustard :
As the application loads we earmark incapable browsers with the above code and exclude the bulk of the Javascript powered UI from them, leaving them with clean, concise, core experience.
Here’s the justification for each condition:-
document.querySelector - A large part of any JS library is its DOM selector. If the browser has native CSS selecting then it removes the need for a DOM selector. QuerySelector has been available in Firefox since 3.5 at least and has been working in webkit for ages. It also works in IE9.
window.localStorage - Although we are not using it yet, we are planning on making considerable use of it. Imagine that if you first came to the mobile site we downloaded all the stories straight away and stored them in localStorage. They’d then be available to use while you are going through an areas of sketchy bandwidth.
window.addEventListener - Another large part of any JS library is event support. Every browser made in the last 6 years (except IE8) supports DOM level 2 events. If the browser supports this then we know it has better standards support than IE8.
*/
if('querySelector' in document
&& 'localStorage' in window
&& 'addEventListener' in window) {
// load the javascript application
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment