Do I need to include jQuery on all pages?

5

Is it necessary to put the script of the production jQuery each time it starts a new encoding?

    
asked by anonymous 06.04.2015 / 04:47

2 answers

5

Yes, you need to put it on every page that will use it. Ideally, it's always the same URL, so it'll probably fetch the browser cache file . Ideally it would be nice to load the default library URL to make it easier for the library file to already be loaded into the cache.

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

Obviously you do not need to put in pages that will not use anything from the library.

    
06.04.2015 / 04:51
2

Not necessarily, if you open a new "page" then yes, it 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 do not 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 "nextPage.html" can have jQuery codes will normally work without passing the <script src="https://code.jquery.com/jquery-2.1.3.min.js"type="text/javascript"></script> tag again

    
16.04.2015 / 21:32