homepage Welcome to WebmasterWorld Guest from 54.198.42.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Advertising - placed by calling an external javascript file
can code be placed in separate file instead of on every page?
Ed_Gibbon




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

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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved