Welcome to WebmasterWorld Guest from 54.226.46.6

Forum Moderators: open

Message Too Old, No Replies

Advertising - placed by calling an external javascript file

can code be placed in separate file instead of on every page?

     

Ed_Gibbon

1:57 am on Sep 12, 2002 (gmt 0)

10+ Year Member



I affiliate with an advertising provider that gives me some javascript code that I place on my webpages.

What are you thoughts on putting this javascript into a separate file, something like banner.js and then calling that with

<SCRIPT LANGUAGE="JavaScript" SRC="banner.js"> </SCRIPT>

from each page that should have the ad.

I have a couple hundred pages that I want to place the advertising on. The javascript is the same for every page. There is not a separate code for each page, no random number or anything. I am thinking that putting the javascript into a separate file would save space on the server, and might also make pages load faster once the script is cached in the visitor's browser and the visitor is loading the second (third, fourth, etc.) page from my site. Is this correct?

Are there any downsides to this? Also there is a <NOSCRIPT> </NOSCRIPT> portion of the banner code. Is there any way it can be included in the separate file?

I am new at this and just feeling my way. Thanks!

jdMorgan

4:32 am on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Ed,

Yes, this should work. Make sure it's OK with the banner provider, though - they might want to check your site to make sure you are serving the banner from n pages, and if they are not sophisticated about it, might miss the external script reference...

I'd recommend you declare the script mime type as well:

<script Language="JavaScript" type="text/JavaScript" src="banner.js"> </script>

For the <NOSCRIPT> section, you could use server-side includes (SSI) to pull in that code. Actually, using SSI to pull in the <SCRIPT> section as well would avoid the problem I mentioned above, if it's contracturally necessary.

Jim

Purple Martin

6:12 am on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



might also make pages load faster once the script is cached in the visitor's browser and the visitor is loading the second (third, fourth, etc.) page from my site. Is this correct?

Yes. That's the idea of external JavaScript files.

Are there any downsides to this? Also there is a <NOSCRIPT> </NOSCRIPT> portion of the banner code. Is there any way it can be included in the separate file?

No. You can't include HTML tags in external JavaScript files. The browser behaves as if the contents of the external file are within

<script Language="JavaScript" type="text/JavaScript"> </script>
tags - in other words, what's in the external file is purely JavaScript, not HTML.

you could use server-side includes (SSI) to pull in that code.

That will work, and will make any updates/edits very easy as you'll only need to edit one file instead of a couple hundred pages, but it won't give you the download advantages of external JavaScript files.

Here is a summary of the difference between the two things:
- You can think of an external JavaScript file as a client-side include which gets cached on the client machine. But it's for JavaScript only.
- SSI gets included in the document by the server so the whole thing (document plus include) gets downloaded every time. It's for both HTML and JavaScript.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month