Hey, I want to detect old browsers and give them a static page saying “upgrade your browser”.
I don’t have the time to go all crazy with feature detection. This package is interesting but won’t work, and it’s client side.:
I’d like to do something serverside like this: https://www.npmjs.com/package/oldbrowser
What’s the best way?
Thanks!
1 Like
Meteor exposes the connect API through WebApp.connectHandlers, you can use that to add the browser restrictions (make sure you add to the top of the stack). We used this approach for a package that implements basic auth for our QA deployments, it should be fairly straight-forward if you use that as a template.
2 Likes
Ah! That’s exactly what I was looking for. Thanks!
I ended up with this:
Meteor.startup(function () {
var stack;
// Add handler
WebApp.connectHandlers.use(function (req, res, next) {
var jalopy = false;
var bowser = Meteor.npmRequire('bowser');
bowser = bowser._detect(req.headers['user-agent']);
bowser.majorVersion = parseInt(bowser.version);
if (bowser.msie && bowser.majorVersion < 11) jalopy = true;
if (bowser.safari && bowser.majorVersion < 9) jalopy = true;
if (jalopy) {
res.statusCode = 307;
res.setHeader('Location', '/old-browser.html');
res.end();
} else {
next();
}
});
// Move handler to the top of the stack
stack = WebApp.connectHandlers.stack;
stack.unshift(stack.pop());
});
2 Likes