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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.