Welcome to WebmasterWorld Guest from 54.145.39.186

Forum Moderators: open

Message Too Old, No Replies

Import Static HTML5 Footer

HTML5, js, ajax, footer

     

EastTexas

11:11 pm on Jan 12, 2014 (gmt 0)



Import Static HTML5 Footer

This only works in Firefox

<script>
var ajax = new XMLHttpRequest();
ajax.open("GET", "footer.htm", false);
ajax.send();
document.body.innerHTML += ajax.responseText;
</script>


This works, but it make the code hard to read since the HTML is warped in JS.

<script type="text/javascript" src="footer.js"></script>

lucy24

12:34 am on Jan 13, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



Tangential answer: What exactly are you trying to do? In English, not in javascript. On the surface it looks like an SSI, but there wouldn't be any reason to use scripting for that.

EastTexas

3:11 am on Jan 13, 2014 (gmt 0)



No SSI used, just some HTML wrapped in JS.

I have some footer content that needs changing at least monthly.

Maybe I should move on to php from static HTML?

lucy24

4:03 am on Jan 13, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



If the content is to be included routinely in every page, not in response to any user activity, then scripting isn't really appropriate anyway.

If you're including static html inside a document that is itself static html, that's an SSI. Sure you can do the same thing in php if you want to, but why bother?

How many different files will this happen to? If the included content only changes every month or so, and you have a high-traffic site, you may want to make cached copies of the finished file and serve those instead.

If you do make it php, you'll have to add a line in your htaccess to parse all html files for php. The alternative is to physically change all your file extensions, and then rewrite from html to php. (Or redirect globally, but that would be silly.) The mechanical details depend on how many files are involved, and what proportion of your total site is involved. There's more than one way to do it.

That was a lot of ifs. Oops.

EastTexas

4:34 am on Jan 13, 2014 (gmt 0)



About a dozen pages.

I didn't think HTML5 & SSI could be mix together?

lucy24

7:18 am on Jan 13, 2014 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



wtf?

News to me.

:: detour to investigate ::

Dammit, search engine, a document that talks about PHP 4 and Apache 1.3 cannot possibly be from the past year.

:: further detour to test site to see for myself ::

Far as I can tell, it doesn't care if the dtd says html 4, html 5 (that is, <!doctype html> only) or no dtd at all. Give or take a mysterious added line break which I'll worry about another time. The <!--#include happens regardless.

graeme_p

7:56 am on Jan 13, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



SSI should work with anything. You may have extra config to do if you want to use SSI with XHTML served as application/xhtml+xml.

@lucy, Google cannot get dates right. It has a lot of page on my site, that have not changed for an year or more, showing dates from the last few months in the SERPS.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month