Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Add a 'safe mode' to the site. #579

Merged
merged 1 commit into from
Apr 4, 2015
Merged

Conversation

toolness
Copy link
Contributor

@toolness toolness commented Apr 3, 2015

This fixes #572 by simply disabling JS if the browser doesn't support a minimal feature set of supported JS APIs (at present, this means CORS). It also allows developers to force-enable this "safe mode" by adding safemode=on to the querystring of any page.

Note that I did look into Modernizr for this but because our detection is so simplistic, I found it easier to just borrow a snippet of code from them rather than create a custom build of Modernizr outright. That said, as I mention in the code comments, if our feature detection becomes more complex, we should probably consider migrating to Modernizr.

function featureDetect() {
var safeMode = /[?&]safemode=on/i.test(window.location.search);
var cors = 'XMLHttpRequest' in window &&
'withCredentials' in new XMLHttpRequest();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it's fine if this code throws an exception--that essentially means that we definitely want to disable JS, and because ENABLE_JS won't be set to true at the end of the function, we'll be in safe mode.

@ScottDowne
Copy link
Contributor

R+

Something I noticed, the list of clubs doesn't show with js disabled. A bug?

ScottDowne added a commit that referenced this pull request Apr 4, 2015
Add a 'safe mode' to the site.
@ScottDowne ScottDowne merged commit 786ade6 into mozilla:develop Apr 4, 2015
@toolness
Copy link
Contributor Author

toolness commented Apr 4, 2015

Thanks!

Something I noticed, the list of clubs doesn't show with js disabled. A bug?

Yeah, I've documented this in #573 (see the third bullet point). Because that content is dynamic and changes w/ user content submissions, it's very hard to make it part of a static site that doesn't use JS; we could for instance trigger a regular cron job that regenerates the static site based on the latest clubs data, which might be a feasible solution if the clubs were the only user-generated content on the site planned in the near future.

However, we're going to be adding lots more UGC in the future, e.g. mentor profiles, so I think it's a better solution to just implement a lightweight dynamic server for v2 that renders views on-demand and aggressively caches them. Another benefit of this is that it will also make it easier for us to support standard, non-ajaxy form submission if we want, which would be a nice accessible solution for no-js folks too. (In other words, I think we should evolve this site so it "gracefully degrades" into a standard web-1.0 style website, but transforms into a badass hovercapable 1962 Chevrolet Corvette if the user's browser is cool enough.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants