Best way to handle older browsers with Sage

Now Sage is using the fancy asset pipeline and versioned filenames, what’s the best way to go about including things like html5shiv.js and respond.js in the head?

Is there a better way to handle old browsers or are they no longer supported?

I suppose they are not supported out of the box. Which versions of browsers are we talking here?

Also, both of the files you mention are Bower packages, so can be automatically included in the build process.

I’m talking ie8. I have a site built with an older version of roots that I would like to upgrade to Sage. Previously I used a conditional to include these files directly in the head if ie8 is detected. How can I do that with Sage now all the filenames of the js files get versioned by gulp? Is there a way to use the assets.json to include the correct file?

Sure, just set the override in your bower.json file with the package name, and set "main" to "", effectively having the build process ignore the package.

Then in manifest.json you could include each file and have it copied to dist, or else you could just reference the files directly from the bower_components folder, but it’d probably be better and cleaner to have those files moved to dist.

@treb0r can’t you use the asset_path function to get the correct versioned filename in all cases?

You can reference it anywhere, but you need to specify the namespace. @kalenjohnson is the expert on namespace stuff.

say head.php

use Roots\Sage\Assets;


<!--[if lt IE 9]>
    <script src="<?= Assets\asset_path('scripts/html5shiv.js'); ?>"></script>

This is assuming you have declared html5shiv as it’s own file in manifest.json. Might also consider putting any IE8 specific stuff in some ie8.js file or something along those lines.

The other thing I might suggest is just using a popular CDN for these IE8 specific JS files, as they’re most likely cached anyways. Then you wouldn’t need to even deal with the Sage asset pipeline specifically for IE8.

1 Like

I know that it’s not your intention, but I often feel stupid after posting on here!

Thanks, you guys rule.