pipedreambomb
pipedreambomb

Reputation: 4020

Executing JS immediately, before everything, in Meteor

I am having massive problems with a Meteor app in IE7. It's probably due to at least one Meteorite package (especially Router I suspect, which specifically doesn't support IE7). I get several JavaScript errors, and a blank page loads with an empty tag.

IE7 bugs affect only 1% of users, but I just hate the idea some people will visit the site and see a blank page and nothing else, and think it's a bad or fly-by-night project.

I'm trying to display a short page I've written explaining that IE7 and lower are not supported, and the user can upgrade her browser, or use Chrome Frame. You can see it if you hit <myapp>/noie.html, as it's saved in the public/ folder.

However, I can't find any way to do a redirect to that page, before the rest of the app comes crashing down, so my redirect code never runs (on production anyway, it does on my machine). I've tried putting it in a file in lib/, I've tried using Meteor.startup()*, I've done both at the same time! But ultimately when you hit the url in the browser, Meteor whirs into action, starts loading dependencies and somewhere along the line, it all breaks.

If I could just get the redirect code to be one of the very first things that get run, all would be okay.

*this seems to get called from client_startup.js, which specifically waits for the DOM to be ready before doing so. It does routing, renders templates etc before getting to my code, which is too late for me.

Upvotes: 0

Views: 544

Answers (3)

jindrichb
jindrichb

Reputation: 96

Relating question is here: Meteor Script Loading Order. And solution is in use of Inject-initial. (Your script/content will be absolutely at first, even before core of meteor)

Upvotes: 0

pipedreambomb
pipedreambomb

Reputation: 4020

I think I'm getting an idea of what to do. You can see by clicking "view source" on a Meteor page (served in development mode) in what order the scripts are getting loaded. Generally speaking, it appears to go:

1) Meteor's own packages

2) Your packages, i.e. those listed in smart.json

3) Functions that have been passed to Meteor.startup() somewhere in your .js/.coffee files

4) The rest of your .js/.coffee files, in a sequence documented under Structuring Your App

Most crucially to me, the order of the smart.json file and resulting .meteor/packages file seems to determine what order the packages get loaded as well.

My plan is now to write my own little smart package that detects IE7 or lower and does a redirect. I will put that in packages as the first item, so it gets run before Router or anything else that might make the app crash on IE7. Will update to say if that works out.

Update: it worked! I've published the package on Atmosphere, simple as it is.

Upvotes: 1

Andrew Wilcox
Andrew Wilcox

Reputation: 1021

If you're comfortable changing your Meteor source you could go here

https://github.com/meteor/meteor/blob/release/0.6.2/tools/server/server.js#L304

and check request.browser, and then return your own "sorry, this browser isn't supported" HTML instead of the regular app html if the browser isn't supported.

Upvotes: 0

Related Questions