Don’t start Aurelia on older browser

I’m looking for some suggestions about how to skip starting Aurelia if using an older browser.

For example, if the user tries to open my application on a browser with no support for the Fetch API - such as Internet Explorer - then I want to show a message saying: “This browser is too old. Get a new one.”

So I don’t want to incur the hit of loading Aurelia, et al for this.

The way it can be done depends on your bundler / packager. Are you using requirejs, jspm or wepback?

Below is the piece I use with the detect-browser package

	<script type="text/javascript" src="~/dist/detect-browser/index.js" asp-append-version="true"></script>
	<script>
		var browser = detect();
		var minVersion = 0;
		switch (browser.name) {
			case "chrome": minVersion = 61; break;
			case "edge": minVersion = 16; break;
			case "firefox": minVersion = 56; break;
			case "ie": minVersion = 11; break;
			case "safari": minVersion = 9; break;
			default: minVersion = 0;
		}
		if (minVersion > parseInt(browser.version.split(".")[0])) {
			window.location.href = window.location.pathname + "/OldBrowser";
		}
	</script>

This comes right before you reference your bundles.

1 Like

Check out
https://discourse.aurelia.io/t/dont-start-aurelia-on-older-browser/1422
which includes my solution later in the post.