PDA

View Full Version : Pop-up javascript code in external file?


Coober
07-07-2005, 05:54 PM
I read somewhere that I should put the code for my pop-up menus in an external file to speed up the page-loading.

If this is indeed possible, where exactly should I put the (pop-up) code and how to access it in my page?

Thanks,

Coober

domedia
07-07-2005, 07:42 PM
Hi Coober,
what this means is that you should place your javascripts in a seperate .js file and call if from the head section of your website.
The benefit of this is that a visitor will cache the javascript file first time it loads, thus eliminating the need to load the javascript as part of your HTML page every time the surfer goes to a new page on your website.

This is how you do it:

1. Locate the javascript in the HEAD section of your page. It will most likely look like this: <script language="JavaScript" type="text/javascript">
<!--
[lots of lines of javascript]
// -->
</script>

2. Copy all the javascript lines to a new document, and save it as 'yourfilename.js' in your websitefolder.
3. Make sure you remove any tags like <script language="JavaScript" type="text/javascript">
<!--
and // -->
</script>
from the .js file.
4. Make a link from your webpage to the .js file in the HEAD area, same area you previously had your whole javascript code:
<script language="JavaScript" type="text/javascript" src="yourfilename.js"></script>


and you should be all done. Make sure you get the paths right, if you place the .js file in a seperate folder on your website, make sure you call the foldername as well from the link in your head section.

Coober
07-10-2005, 08:32 PM
Thanks, just what I needed!

Coober