Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2 Asset Pipeline + html5shiv.JS in vendors/assets/javascript

After reading this post (recommended reading) about not using HTML5Shiv direct from source like (almost) everybody does, I'm trying to include the html5shiv.js in my app using Rails 3.2 Asset Pipeline.

I downloaded both minified and not-minified version of the javascript. The convention tells you to add third-party files into the vendors/assets folder. I have two questions now:

1) Which version (minified or not-minified) should I add to vendors/assets/javascrip folder?

2) Since it's a conditional reference <!--[if lt IE 9]>, how should I call the script?

I don't want to add it to the application.js manifest, because I want to keep it as a separate file and I want to use the condition. I'm kind of lost!

Any help would be very appreciated.

Thanks

like image 517
Guillermo Guerini Avatar asked Jul 05 '12 13:07

Guillermo Guerini


1 Answers

You can use the unminified version of the JS if you like, Rails will compress it in production mode through the pipeline.

To keep the shiv as a separate file you can give it it's own manifest by creating a html5.js (or whatever) in your /vendor/assets/javascripts/ directory. In that file require the html5shiv (I assume the manifest and script are in the same dir).

//= require html5shiv

or

//= require html5shiv.min

And then include the manifest in your layout in the conditional block. In HAML something like:

== "<!--[if lt IE 9]>"
= javascript_include_tag 'html5'
== "<![endif]-->"

Remember to restart your app server before testing.

like image 166
Blake Simpson Avatar answered Sep 17 '22 23:09

Blake Simpson