Created
          August 3, 2012 14:48 
        
      - 
      
- 
        Save adamrobbie/3248305 to your computer and use it in GitHub Desktop. 
    Rails Helper to call javascript asynchronous 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | module AsyncHelper | |
| def javascript_async(*args) | |
| content_tag :script, type: "text/javascript" do | |
| "(function() { | |
| var script = document.createElement('script'); | |
| script.type = 'text/javascript'; | |
| script.async = true; | |
| script.src = '#{j javascript_path(*args)}'; | |
| var other = document.getElementsByTagName('script')[0]; | |
| other.parentNode.insertBefore(script, other); | |
| })();".html_safe | |
| end | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment