3

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 jquery-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!

TylerM
  • 161
  • 2
  • 11

1 Answers1

3

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.

nobody
  • 1,782
  • 17
  • 28