Do I need to include jQuery on every page?

Asked

Viewed 326 times

5

It is necessary to place the script jQuery production every time you start a new encoding?

  • 1

    What would be the "production script"?

  • <src="js/jquery-1.11.2.min. js"></script>

  • All you have to do is call the documents and you will use jQuery. Related: http://stackoverflow.com/questions/28919023/trouble-making-animating-boxes-in-jquery

  • Thanks! I need to leave the JS file in all the folders you will use then?

  • Barbara, did you see the answer below? The ideal is to use an external link, as the bigown suggested. This saves you from keeping a copy of jQuery in your project.

  • Okay. Thanks for your help.

Show 1 more comment

2 answers

5


Yes, it is necessary to put on all pages that will use it. And ideally it is always the same URL, so it probably take the browser cache file. Ideally it would be good to load the standard library URL to make it easier for the library file to be already cached.

<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>

I put in the Github for future reference.

Obviously you don’t need to put in pages that won’t use anything from the library.

There is a trick to not need to write this on every page, but it is something more sophisticated and may not work in all situations and can complicate SEO if necessary.

jQuery nowadays is virtually unnecessary.

  • Thank you very much!

2

not necessarily, if you are going to open a new "page" then yes, you will have to load, but if you use only one page and all the rest are loaded through a javascript function for example, in this case the previous script will remain loaded, then you won’t need to reload the file.

example in index

<html>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>        
      ...
<script>
    $("div").load('proximaPagina.html');
</script>
</html>

this "proximaPagina.html" can have jQuery codes will usually work without passing the tag <script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script> again

Browser other questions tagged

You are not signed in. Login or sign up in order to post.