homepage Welcome to WebmasterWorld Guest from
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

Is there a downside to replacing a lot of HTML with Javascript?

 10:39 pm on Feb 11, 2011 (gmt 0)

Hello, All. First Post.

Is there a downside to replacing most non-content portions of HTML pages with Javascript?

When I can fit it in, I'm a part-time Webmaster for our organization's site. I am weary of uploading hundreds of pages when I want to change something on the headers or footers.

I have about 3,000 pages of static archives, and 30 or 40 pages that are updated regularly. I'd like to be able to change the header and footer of the whole site once in a while without having to upload every page again.

I've used a lot of CSS to style everything (easy to update), but it is the text and links of the headers and footers that I'd like to replace entirely with Javascript.

Would it be too weird to do something like this?

I'm not looking for an examination of my code just yet, just opinions on whether or not it would be a problem to use "document.write ..." for so much.



<link rel="stylesheet" type="text/css" href="../style/styles.css" />



<!-- banner here -->
<script type="text/javascript" src="../scripts/banner.js"></script>

<!-- a list of links to current content here -->
<script type="text/javascript" src="../scripts/current_links.js"></script>

<!-- content here -->
<p>A couple of thousand words of content would be here, nice and tidy.</p>

<!-- footer here -->
<script type="text/javascript" src="../scripts/footer.js"></script>



The files "banner.js", "current_links.js" and "footer.js" would be something along these lines:

document.write(' <div id="banner"> MyWebSite Info <a href="../new.htm">NEW STUFF</a> | <a href="../old.htm">OLD STUFF</a> etc., etc. </div> ')

The test that I've done loads like a rocket, is super easy to update, and the code is squeaky clean. It seems TOO easy. What's wrong with the plan?

Thanks for your input.




 10:50 pm on Feb 11, 2011 (gmt 0)

I would NOT recommend that.

Two main issues..

1) The search engines don't do javascript well. G is better about it than Bing, but I'm still not convinced that links found by G within javascript carry the same weight as regular hypertext links. For any search engine that doesn't handle javascript, or doesn't handle it well, you will effectively kill your site as they won't be able to find the links to the internal pages.

2) Any user that has JS off will not be able to use your site at all.

Why not achieve the same thing via a server-side include. You should have that ability regardless of the platform the site is based on.


 11:13 pm on Feb 11, 2011 (gmt 0)

The problem with that is that we have years worth of backlinks to our site. If I changed it to .shtml, all of those links would break. They aren't the kind of links we want to blow off.

Is there a way to use ssi without filenames ending with .shtml?


 11:14 pm on Feb 11, 2011 (gmt 0)

To address the search engine thing, I generate a sitemap.xml every time I add pages. Would that be enough?


 11:31 pm on Feb 11, 2011 (gmt 0)

If you have PHP on the server then use PHP includes.

You do NOT need to change the filenames or extensions, but you will need to tell the server to interpret .html (or whatever you use) files as able to contain PHP instructions.

Do not use JS. It is the wrong solution.


 11:36 pm on Feb 11, 2011 (gmt 0)

As g1smd said, it sounds like you are on an apache server. if that is correct, then it's a fairly simple matter of telling the server to either parse the files for cgi commands or as g1smd recommended, parse the files as php and use a php include.

The sitemap is NOT enough. Just find a way to use a server-side include. The javascript solution will absolutely kill your site.


 11:43 pm on Feb 11, 2011 (gmt 0)

Welcome to WebmasterWorld.
You could configure your server to process .htm or .html files as server side includes as well. But I would recommend against using JavaScript for this purpose. JavaScript is best used to progressively "enhance" a page (vs. relying on it as a requirement).


 2:08 am on Feb 12, 2011 (gmt 0)

Thank you!

It sounds like Javascript No and PHP Yes.

Yes, Apache on Linux.


 5:13 am on Feb 12, 2011 (gmt 0)

Is there a way to use ssi without filenames ending with .shtml?

top of .htaccess

AddType text/html .shtml
AddHandler server-parsed .htm
AddHandler server-parsed .html
AddHandler server-parsed .shtml


 1:49 pm on Feb 12, 2011 (gmt 0)

That worked for me. Thank you all. It does just what I need.

And then I found the instructions at my Web host. :-)


Created the .htaccess file in a folder with Transmit, opened the file and added the lines:

AddHandler server-parsed .htm
AddHandler server-parsed .html


 3:04 pm on Feb 12, 2011 (gmt 0)

While SSI allows simple includes, using PHP will allow you to do a lot more.


 5:23 pm on Feb 12, 2011 (gmt 0)

g1smd: I'll see what I can learn at [tuxradar.com...]

Maybe you can teach an old dog new tricks.

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