performance - Is including unused JavaScript files a bad practice? -


i use jquery in lots of websites, obvious reasons. include in header.php file. include other javascript libraries in end this:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script> <script type="text/javascript" src="http://example.com/js/classes.js"></script> <script type="text/javascript" src="http://example.com/js/common.js"></script> 

there more includes, , of them use in 1-2 pages. practice include these javascript files in every other page too? decrease performance? mean, know have downloaded first time, cached after it, won't they? so how including (without using it) affect performance? how cached files change situation?

if affects performance, should like:

<?php if (jsfileneeded) { ?>    <script type="text/javascript" src="http://example.com/js/classes.js"></script> <?php } ?> 

what other techniques can use rid of unused file includes?

i'd recommend using requirejs javascript dependency needs: http://requirejs.org/. possibly more elegant solution using backend code turn on , off script tags.

either way bad idea include files unused, if they're cached still take memory. if they're not cached connections , more bits on wire slow down pages.

on broadband connection unused files unlikely make difference. if page viewed on phone on intermittent data connection make page slow or fail load.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -