More Info


You are in: home > javascript > javascript space saver >

JavaScript space saver

If you repeat lengthy pieces of HTML a lot in your pages you can use code similar to this to cut the download time dramatically.

I used this in a page used for selecting colours in part of the Quest-net site. In Quest-net there's a system for users to create their own website. There were 10 drop-down boxes each with 140 colours in them to design the page layout. To make the page a more reasonable size I loaded the colour names and values into a JavaScript array:

The drop-down box could then be written 10 times using the following JavaScript:

Doing it this way resulted in a 28kb file. A saving of approximately 70kb.

Demo 1 - 10 Select elements of 130 items - 65Kb

Demo 2 - 10 Select elements using the space-saver - 13Kb






 © James Austin 2002-05 Web site design by James Austin