Created
November 25, 2010 18:27
-
-
Save fnando/715765 to your computer and use it in GitHub Desktop.
jQuery from Google CDN with local fallback for Rails apps
This file contains 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
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script type="text/javascript"> | |
if (typeof jQuery === "undefined") { | |
document.write(unescape("%3Cscript src='<%= compute_public_path("jquery-1.4.4.min.js", "javascripts") %>' type='text/javascript'%3E%3C/script%3E")); | |
}; | |
</script> |
É a primeira versão. O problema é que criando o elemento e dando append, você não consegue garantir a ordem de carregamento dos scripts. Já com o document.write, ele faz blocking enquanto o script não for carregado.
Ah, bom saber. Abraço
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
não é melhor criar o elemento e dar um append no head?