Welcome to WebmasterWorld Guest from 50.19.156.19

Forum Moderators: open

Message Too Old, No Replies

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

     

Rebby_mac

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.

<html>

<head>

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

</head>

<body>

<!-- 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>

</body>

</html>


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.

Reb

Philosopher

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

WebmasterWorld Senior Member 10+ Year Member



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.

Rebby_mac

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?

Rebby_mac

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?

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

Philosopher

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

WebmasterWorld Senior Member 10+ Year Member



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.

Fotiman

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

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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).

Rebby_mac

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



Thank you!

It sounds like Javascript No and PHP Yes.

Yes, Apache on Linux.

tangor

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

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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

Rebby_mac

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

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

Rebby_mac

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.