Skip to content

Instantly share code, notes, and snippets.

@fnando
Created November 25, 2010 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnando/715765 to your computer and use it in GitHub Desktop.
Save fnando/715765 to your computer and use it in GitHub Desktop.
jQuery from Google CDN with local fallback for Rails apps
<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>
@alissonsales
Copy link

não é melhor criar o elemento e dar um append no head?

@fnando
Copy link
Author

fnando commented Nov 26, 2010

É 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.

@alissonsales
Copy link

Ah, bom saber. Abraço

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment