Question

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

Was it helpful?

Solution

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.

OTHER TIPS

Or you may use directly

/[if lt IE 9]
  %script{ src: "http://html5shim.googlecode.com/svn/trunk/html5.js", type: "text/javascript" }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top