Everyone has JavaScript, right?
- Your user requests your web app
- Has the page loaded yet?
- “All your users are non-JS while they're downloading your JS” —
Jake Archibald
- Did the HTTP request for the JavaScript succeed?
- If they're on a train and their net connection goes away before your JavaScript loads, then there's no JavaScript.
- Did the HTTP request for the JavaScript complete?
- How many times have you had a mobile browser hang forever loading a page and then load it instantly when you refresh?
- Does the corporate firewall block JavaScript?
- Because loads of them still do.
- Does their ISP or mobile operator interfere with downloaded JavaScript?
- Sky accidentally block jQuery, Comcast insert ads into your script, and if you've never experienced this before, drive to an airport and use their wifi.
- Is the user a microbrowser, getting details to embed in another
app?
- Microbrowsers
are everywhere, every time someone pastes your URL into a chat app
or a social media tool and it shows a preview, and they aren't going to
wait for your 2MB client app to boot up.
- Have they switched off JavaScript?
- People still do.
- Do they have Chrome's Data Saver mode turned on?
- If they do, and they're on a 2G or otherwise slow connection,
Chrome will
disable all scripting.
- Do they have addons or plugins installed which inject
script or alter the DOM in ways you didn't anticipate?
- There are thousands of browser extensions. Are you sure none
interfere with your JS?
- Does their adblocker block a script you’re accidentally
dependent on?
- Many
people use adblockers, which may blanket-block whole domains.
If you have one script dependent on another and that other script gets
blocked, the remainder of your scripting may not start up.
- Is the CDN up?
- CDNs are good at staying up (that’s what being a CDN is) but a minute downtime a month will still hit users who browse in that minute.
- Does their browser support the JavaScript you’ve written?
- Check Can I Use for browser usage figures.
Is all the above true?
Then yes, your JavaScript works.
Probably.
Progressive enhancement. Because sometimes your JavaScript just won’t work.
Be
prepared.
Russian
translation available at Frontender
Magazine courtesy of Антон Немцев.
These are by no means all the reasons why your JavaScript
might fail to run even when you expected it to. Andy Bell
has a great list over at piccalil.li of
a handful of very realistic reasons JavaScript won’t be available. Check ’em out, and be prepared.