0

I have seen in code the following:

<script>window.jQuery || document.write('<script src="js/jquery-1.7.min.js">\x3C/script>')</script>

I have also seen include tags for jquery as follows:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>

Which is better to use and why?

chell
  • 7,646
  • 16
  • 74
  • 140
  • 1
    The first one is assuming it's been loaded, and checks with `window.jQuery`. If that fails, it loads the local asset with `document.write(..)`. The second one just loads the asset from local, but adds a query string so that they can control caching. In my opinion the first one is probably better - using a cdn it's more likely a user has jQuery cached already from the cdn - plus it's less bandwidth you have to serve. – Prescott Mar 19 '12 at 05:36
  • 2
    Follow this link.. you will get answer with detail http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-go – ABHISHEK Mar 19 '12 at 05:38
  • Thanks Prescott and ABHISHEK for your answers. – chell Mar 19 '12 at 08:11

0 Answers0