views:

348

answers:

6

Hello,

I have a PHP application in which there is a div container which includes the app which has been $_GET from the URL string.

Currently, there are two applications which require TinyMCE, and one application which requires jQuery and jQuery UI.

Question is, where should I include the files on the page?

In the header, the page loads really slowly, >30 seconds (now <10 seconds, using different router), at at the bottom, the pages which require the scripts fail to load correctly.

The JS files have already been minified and compressed.

TinyMCE won't gZIP becuase Zlib is installed (as a result of GD), so how should I optimise the situation?

+2  A: 

At the bottom and run your scripts when the document is fully loaded (using "onload" event).

Adam Dziendziel
the only script that fails now is tinymce, becuase it wants everything to be loaded before the textbox tag is called.
Shamil
+4  A: 

The Yahoo! Exceptional Performance team recommends to put the script elements at the end of the body element.

Gumbo
Nope, scripts fail :|
Shamil
Then you should fix that script. Find out why it fails and fix it.
Gumbo
having said that, the only script that fails now is tinymce, becuase it wants everything to be loaded before the textbox tag is called.
Shamil
The example on its website works fine even when the script is loaded after the form.
Gumbo
I can't seem to find the page to which you are refencing.
Shamil
Here: http://tinymce.moxiecode.com/examples/full.php
Gumbo
+1  A: 

By placing the JavaScript file just before the closing BODY tag, you are allowing the rest of the page to load while the JavaScript file is loading. If you place it in the HEAD section, the page will hang until the script loads.

If it's taking 30 seconds to load in the header, though, you are probably facing a different issue. TinyMCE should not take 30 seconds to load.

James Skidmore
I think the 30 seconds was more becuase of my awful connection now - using another router brings it way down under 10 seconds.
Shamil
+1  A: 

There probably is no one correct answer for this.

Generally placing javascript to <head> works fine, but 30 seconds is way too much. I'm developing a JavaScript app which dynamically loads about 70 uncompressed javascript files (some quite large) and it doesn't take anywhere near 30 seconds.

Too little information to solve this.

Rene Saarsoo
Ok - 30s must have been due to my bad connection - now seeing under 10s
Shamil
+1  A: 

How many JS files is it? If its many, then you may want to look at Steve Souders slides for Even Faster Websites. Downloading JS file is a blocking action. Souders has a nice solution for dealing with script blocking. Check the PPT from http://www.thebitsource.com/2009/03/14/sxsw-interactive-2009-steve-souders-on-even-faster-web-sites/

Also, where are you serving the JS from? Try serving jQuery from Google AJAX Libraries API. It uses their CDN and caches for a long time. So the user will only have to dl the files 1 time.

frio80
There are 3. Becuase of the nature, it'll be on an extranet, and an intranet, loading from a CDN isn't an option, but I'll include it from the extranet point of view, and return what happens :)
Shamil
A: 

I want my JS Code be completely seperated from the XHTML, thus putting it inline HTML before the body closing tag won't do for me.

I declare one single JS File in the html head. Then copy/paste all Libraries etc into that JS file. This will result in one HTTP Request, which speeds things up on mobile browsers too.

I then use Prototype to get DOM sensitive functions started:

document.observe("dom:loaded", function) { // code goes here });

Stephan Kristyn