[SOLVED]
I use to create pages, usually without javascript, and only then add javascipt functions. That way, I can set all the divs with tools that require javascript with the display: none, and then in the first line on javascript to make it visible:
<script type="text/javascript"> $(document).ready(function(){ $('#jsdivs').show(); }); </script>
In doing so, I avoid people who, for whatever reason, have disabled their browsers.
Following this spirit, I would like to find a way not to load javascript by default, and then if javascript is enabled, there are instructions for downloading javascript files.
I am currently loading jQuery like this (for caching reasons, many people may already cache):
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
And another file with all other javascript is minimized. Everything is at the end, immediately before the HTML tag tag.
I have seen many opinions here and here , but none of them will help me with this. First, I would like to know if this is good. Thank you very much.
UPDATE:
@ Lèse majesté showed me an old discussion about how browsers don't download javascript files when they are disabled . Since I did not think the information was convincing enough , I conducted several tests by disabling javascript in Firefox through the “Web developer” plugin, and YSlow (another FF plugin for Firebug) continues to show all javascript information, not to mention that "Live Headers" (another fantastic FF plugin that shows real-time headers) also showed that the _utmc cookie was present in the request (via the Google Analytics script).
@Marcel Korpel made a very good comment (albeit a snob), which paved the way for a real solution. he said that Google Analytics uses the "method to dynamically enable ga.js. The closing tag (and the immediately opening tag) is necessary for the browser to update the DOM tree and actually load and execute the added script."
With information about it, I could find this PHP code (I had to put the PHP code in Pastie.org because Stackoverflow was messing with it):
http://pastie.org/1487432
What prints:
<script language="javascript" type="text/javascript"> document.write('\<script src\="js\/minified\.js" type\="text\/javascript"\>\<\/script\>'); </script>
This time, YSlow and Live Headers say nothing about the javascript file.
Roger source share