Forum Moderators: open

Message Too Old, No Replies

How to speed up page load with .js included

it's a simple text navigation menu

         

walkman

9:32 pm on Mar 10, 2007 (gmt 0)



I replaced my menu with a .js but the page is loading noticeably slower. The menu file is 5.21 kb and the other .js file is 1.10 kb. Essentially it's the same as the text (give or take a few 100 bytes), but it's taking much longer. Is there a way to minimize the loading time?
the file to be included is like this:

document.write(''
+ ''
+ '<a href="/

and I call it where the text should appear with <script type="text/javascript" src="/images/menu.js"> </script>

thanks in advance,

penders

10:50 pm on Mar 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There is additional overhead (http requests) with having separate files. But I would have said this was minimal with just a couple of small files - not enough for it to 'take much longer'? Unless there was some kind of delay server side?! Subsequent requests should be a lot quicker, as the JS file should be pulled from the clients cache...?!

I don't know if there would be any change in page load, if the JS files were included in the <head> section, and a function called where the JS files are currently included?

A side issue... bare in mind that a menu written entirely with JS (apart from being unavailable to those without JS) will not be spidered by the search engines.

walkman

12:01 am on Mar 11, 2007 (gmt 0)



Hi Penders,
thanks. I think my connection is slower right now...that's why. I tried to dload a huge backup file and now I am noticing it. I have cable so I never had to worry about speed, that's why it didn't hit me.

And, yes, I am doing it so google does not index it. This is for the product pages so I want to avoid any dupe issues. The normal menu is in on "enough" pages already.

Thanks again. I think the speed of my connection was it...but will check again.

ultraniblet

12:01 am on Mar 11, 2007 (gmt 0)

10+ Year Member



Personally I find multiple http requests to separate js files are a real wildcard, sometimes no difference and other times slowing things down significantly.

If you have control of the server, why not PHP file_get_contents all of your scripts into one, and zip before serving.

walkman

3:57 pm on Mar 11, 2007 (gmt 0)



ultraniblet,
why would a .js request be any worst than a ssi include? In my case it's essentially an include; no calculations or text manipulation at all: just get the text, and add it. I am not that familiar with javascript

Now that my connection is fast, I see not sign of it at all.

Thanks to all

penders

10:09 pm on Mar 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



why would a .js request be any worst than a ssi include?

A .js request is another http request from client to server. A SSI include all happens on the server and comes down as 1 (bigger) response. I wouldn't have said a couple of .js requests would/should be any worse? And the JS file caches nicely, which is a bonus.

However, ultraniblet also mentions compressing (gzip) the file (server-side) before sending which can greatly reduce file size / download time / bandwidth.
[webmasterworld.com...]

walkman

11:09 pm on Mar 11, 2007 (gmt 0)



penders,
thanks. At most I'll have less than 6-7kb in 2-3 files.

rocknbil

7:45 am on Mar 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



walkman does your menu.js file use the document.write() method to create the menus? If this is the case this may be what's slowing things down, not the file size. I had a horrible experience with those types of menus a few years back, as the menus got larger and larger the page became slower and slower.