user4055428
user4055428

Reputation: 1167

Using JavaScript to inject reusable content into webpages?

I'm sorry if this is considered too general a question. I have a website that I'm creating from scratch and without any CMS or fancy tools. I have like 20 lines of HTML that compose the header that is the same on every page. So it seems logical that I should use document.write(header) inline where the header needs to be on each page, and before that have a way of grabbing the HTML for the header from a local HTML file.

Upvotes: 0

Views: 93

Answers (2)

Aldo Sanchez
Aldo Sanchez

Reputation: 450

It's probably much better/easier if you look into templating languages such as Handlebars.js.

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114417

You can do this using AJAX - on page load, insert the contents of some URL into a DIV. The problem with this technique is that it really sucks for SEO - crawlers will see that page without the loaded content.

NEVER use document.write because it stops page execution and can only be used effectively DURING load time, not AFTER.

Upvotes: 1

Related Questions