Web Hosting Talk







View Full Version : .shtml or .js?


(SH)Saeed
12-31-2000, 05:30 PM
Hi all,

I have been using .js files to import some of the common html and javascript that all my websites pages use. This lets update all pages by editing one file (the .js). When a page is loaded it calls 4 .js files. What I'm wondering is if calling .js uses more resources than using SSI (.shtml), or is it basicly the same?

Saeed

JL™
12-31-2000, 07:27 PM
SSI uses more resources than a .js file. With SSI enabled, every page sent from your server is read by the server first, then sent to the person who requested it. This "read" of the pages slows the server down. With a .js file and SSI disabled, the server simply sends the pages to the browser (without reading it) and the browser then calles the .js file, not the server. Therefore, the .js file uses the same amount of resources as any other text file.

GHDpro
12-31-2000, 07:27 PM
Well, if you include the ".js" files with the following
HTML code:
<script language="javascript.js"></script>
This HTML code will be executed on the client (browser).
For loading the entire page (assuming you have 1 .html page
and 4 .js files), 5 HTTP connections are required. So
although the including is done on the client, it's probably
slower overall and will put a higher load on the server.

If you include ".shtml" files with the following HTML code:
<!--#include virtual="/include.shtml"-->
This code will be parsed by the webserver. Parsing the HTML
and including the files will require some processing by the
server - but IMHO, I think this will always be less of a
load than having 4 extra HTTP connections (which require
4 seperate HTTPD processes) as required in the ".js" file
technique... Also as far as I know you can't include HTML
code with the ".js" file trick - only script code.

These are just my thoughts... Anyone disagree?!? ;)

Lawrence
12-31-2000, 08:06 PM
The other thing to consider is search engines. If the pages with the .js file are to be indexed by search engines, you probably want to use SSI. I'm not sure about this, but I would think the JavaScript calls are ignored by search engines, whereas SSI ones are not (as the server does the SSI before handing the page over to the search engine).

Of course, it might be strategic to use the Javascript so that the search engines ignore it.

(SH)Saeed
12-31-2000, 08:10 PM
I don't know about the server load, I hope someone can give me an answer to that (as right now there is to different answers). :confused:

GHDpro,
about .js not being able to do HTML, that is wrong. You can simply include HTML (or anything else) by this method:

document.write('<img src="picture.gif" alt="monkey man">\n');


Saeed

(SH)Saeed
12-31-2000, 08:15 PM
Lawrence,

Hmm.. I have like 100 .html files and they all have the required meta tags for the engines, why would the search engines ignore them? The only parts that are called from .js is advertisement (banners codes) and the site menu (since I change it every now and then).

I need to use one of these options. It would be a pain to go through 100+ pages everytime you want to change something.

Saeed

Lawrence
12-31-2000, 08:23 PM
zolbian -

I meant that I'm not sure if the parts printed by the JavaScript files would get indexed. The page itself, however, would. Obviously, if it's just advertisements, then it's not really a problem. But if it's menus and you'd like the search engines to spider your page, then it might be a problem.

I'd recommend SSI, however. Relying on the client for displaying banners etc could get messy.

(SH)Saeed
01-01-2001, 06:12 AM
I changed everything to SSI and now I have run into a problem! Some of the pages (i.e. search) is written by a CGI script. The SSI won't work in these ;( Is there anyway to fix this?

Saeed

Lawrence
01-01-2001, 07:00 AM
Sort of...

SSI won't work in CGI scripts because pages printed through CGI don't get parsed by the server.

However, if you're just calling in HTML pages using SSI, it's not too hard to emulate. If you're calling in other CGI scripts with SSI, it may get a little complicated.

Do you know perl? And is that what the search script is written in?

(SH)Saeed
01-01-2001, 10:42 AM
Yeah, I know Perl and itīs no bigger problem changing the script to read those files and put the text where it belongs. Just thought I ask to see if there was a better way, cause I have about maybe 10 scripts that I need to edit for this.

Saeed

(SH)Saeed
01-01-2001, 12:30 PM
Ok, I wrote my own little SSI script that searched for the SSI tag and replaces it with the correct file. For this I had to add 2 subroutine to each .cgi script. But I guess itīs worth it!

Saeed