Tips for adding jquery to webpage

Facebooktwittergoogle_pluslinkedinmail

Hosted jquery library or jquery file hosted in my own server -which is good for performance ?

you can either put jquery file in tour server or you can link to popular hosted libraries from big names like google , microsoft etc for jquery file usually in the head tag.

for emample: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

if you use hosted libraries like google it will be likely faster than loading time required  for jquery library file put in your server.Populer hosted libraries will be loaded from cache because visitor already  might have visited websites using these library.In case vistor has not downloaded this , after first time visit ,it will be  cached.

More over google will load jquery library from nearest server from vistor’s geographic location to speed up loading time.

Minified or uncompressed jquery library which will perform better?

Always  use minified version  for production. it will reduce loading time and improve performance.

Point to consider when using  SSL enabled website?

If you are using ssl certificate in your website  you must use secured server links for hosted library.

eg. https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js this source is correct.

But http://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js but this source is not correct in this case. Please  Be careful about https://.

In fact in your secured site all external links should be from  HTTPS not HTTP.

Async And Jquery

<script async> tag is   new in HTML5.It will make the script run asynchronously , if you add a jquery file like this <script async src=”jquery.js”/>  , sometime one see some functions using jquery may not work. Function may be called before the jquery library is loaded asynchronously so functions using library will not work.

you can find some solutions here or remove tag.

 

 

 

 

 

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *