I have a page, php and javascript. Sometimes, the javascript files do not load, then my page will work properly.
I have include 5 javascript file (jQuery plug-in), i want to know:
- how can i improve javasccript loader?
- how can i reload the scriptfile if the script files do not loaded properly?
I have checked when the php page takes more than 10 sec to load the page will be broken.
Thank you
Tip #1:
Have the Javascript files load at the end of your page.
Javascript does not need to be send over
HTTPso soon, as it’s use is only for dynamic changes after the page is loaded.Move:
to the bottom of the page.
Tip #2:
In addition, try and maintain your Javascript code in two versions:
Sandbox: Your version of the code which is divided nicely into modules.Release: The website’s version of the code which is placed all into one Javascript file and minified using something like YUI Compressor. This reduces the file size and increases load speed by decreasing the amount ofHTTP requestsaccordingly.Tip #3:
Replace:
<script type="text/javascript" src='src/jquery_1.7.min.js' ></script>with:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>Most users today have the Google API version of jQuery cached so this loads much faster than having to load your version on hand.
Enjoy and good luck!