Hi,

What would you think to add a fallback option to javascript_include_tag?

If I load dojo from Google CDN, I'd like a fallback. The easiest way to do
so is by putting a script tage right after it:
<script>typeof(dojo) === "undefined" && document.write(unescape('%3Cscript
src="assets/javascripts/dojo.js"%3E%3C/script%3E'));</script>

But the dojo library should go in your /vendors/assets/ not in your
/public/assets. To get it served, I need to play with the
config.assets.precompile if I understand well. Anyway, it all seem very
hacky too me.

What would you think of being able to do something like that:

= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js", :test => 'typeof(dojo) === "undefined"', :local => 'local/path/to/dojo'

That way rails take care of putting the extra <script> tag for us with the test and most importantly, can precompile the file and set the good path.

What do you think?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/R6SI2KVerccJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Tim Shaffer at Oct 18, 2011 at 1:11 am
    Why not just something like this? Then you can put your dojo.js in
    assets/javascripts and compile it like normal. Seems kind of unnecessary to
    add extra logic to javascript_include_tag

    <%= javascript_include_tag
    "http://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js" %>
    <script type="text/javascript">
    if ( typeof(dojo) === "undefined" ) {
    script = document.createElement('script');
    script.type = "text/javascript";
    script.src = '<%= asset_path "dojo.js" %>';
    document.getElementsByTagName('head')[0].appendChild(script);
    }
    </script>

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/uLhgXEinLwoJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Karel at Oct 18, 2011 at 10:11 am
    Hi Tim,

    That's what I'm doing and it works just fine.

    Though the second <script> tag belongs to the first one and could be
    generated/linked to it.

    It is just an idea that would make it cleaner and more self contained.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/CubTUihIYjgJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Tim Shaffer at Oct 18, 2011 at 11:51 am
    Gotcha. You could always create a helper for it.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HweoZagzy1cJ.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 17, '11 at 8:50p
activeOct 18, '11 at 11:51a
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Karel: 2 posts Tim Shaffer: 2 posts

People

Translate

site design / logo © 2022 Grokbase