Rails 3 Conditional Inclusion of Javascript files
I'm trying to figure out the best way to include the following in my head in rails 3:
<!--[if IE]><script language="javascript" type="text/javascript" src="/javascripts/excanvas.min.js"></script><![endif]-->
As you can see, I just want that javascript file availabe to IE... so perhaps I shouldn't do it this way at all... I'm open to suggestions.
I'm using this to specify the default javascript files for inclusion:
config.action_view.javascript_expansions[:defaults] = %w(jquery rails jqu开发者_如何转开发ery-ui jquery.flot)
Is there anyway I can specify this excanvas.js in the defaults only if the user is using IE?
What's the best way to do that?
Thanks!
The best way is the way you're doing it, i.e.:
<%= javascript_include_tag :defaults %>
<!--[if IE]><%= javascript_include_tag "excanvas.min" %><![endif]-->
Conditional comments, rather than serverside useragent scraping, are the best way to go about serving additional CSS/JS assets to IE/specific versions of IE. Some proxy servers modify the User-agent header which means that some IE users might not have the excanvas
file inserted into the :defaults
expansion. Inserting it like this means all IE users will be served the file, not just those where the user-agent matches a typical IE useragent.
精彩评论