admin管理员组

文章数量:1327284

I'm trying to load JQuery from //ajax.googleapis/ajax/libs/jquery/1.9.1/jquery.min.js:

<script src="{{ asset('//ajax.googleapis/ajax/libs/jquery/1.9.1/jquery.min.js') }}"></script>

If the file is received, then get it. If not, get the file from the own server:

<script><window.jQuery || document.write('<script src="{{ asset("../app/Resources/public/js/vendor/jquery-1.9.1.min.js") }}"><\/script>')</script>

but it gives me a syntax error. I've tried to scape the quotes but doesn't work:

<script><window.jQuery || document.write('<script src="{{ asset(\"../app/Resources/public/js/vendor/jquery-1.9.1.min.js\") }}"><\/script>')</script>

It gives me again a syntax error. What am I doing wrong?

I'm trying to load JQuery from //ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js:

<script src="{{ asset('//ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js') }}"></script>

If the file is received, then get it. If not, get the file from the own server:

<script><window.jQuery || document.write('<script src="{{ asset("../app/Resources/public/js/vendor/jquery-1.9.1.min.js") }}"><\/script>')</script>

but it gives me a syntax error. I've tried to scape the quotes but doesn't work:

<script><window.jQuery || document.write('<script src="{{ asset(\"../app/Resources/public/js/vendor/jquery-1.9.1.min.js\") }}"><\/script>')</script>

It gives me again a syntax error. What am I doing wrong?

Share Improve this question asked Oct 29, 2013 at 12:55 ManoloManolo 26.5k21 gold badges89 silver badges134 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

You can check it with this piece of code:

<script src="http://ajax.aspnetcdn./ajax/jquery/jquery-2.0.0.min.js"></script>
<script>
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='/js/jquery-2.0.0.min.js'     type='text/javascript'%3E%3C/script%3E"));
}
</script>

You can find the full article with this piece of code here: Jquery CDN fallback

I've finally achieved doing:

<script>
if (typeof jQuery == 'undefined') {
document.write('{% javascripts "../app/Resources/public/js/vendor/jquery-1.9.1.min.js" %} <script src="{{ asset_url }}"><\/script> {% endjavascripts %}');
}
</script>

Try something like this:

<script>
//try to Include from google here

if (typeof jQuery == 'undefined') {
//if not included local source
}
</script>

本文标签: