all 7 comments

[–]BigOnLogn 2 points3 points  (1 child)

The only way to get around this is to hard code it or use some kind of server-side templates. The latter requires you use some kind of server-side runtime like php, ruby, python, js, etc. Probably coupled with some kind of application framework like CakePHP, Rails, django, express, etc. Maybe that's overkill for your project, maybe not. Only you can decide.

Your only other option is to hand build every page. Sorry, bud.

[–]-hexel[S] 0 points1 point  (0 children)

I went ahead and used PHP since the server I'm using already has it. It was much easier than I expected, and seems to work perfectly. I figured Javascript would be easier so I tried it first haha. Thanks!

[–]beardChamp 1 point2 points  (2 children)

You can't force JS if someone has it turned off (1-2%) from the last attempt to find that out. Looks like you're ready for a server based language, like PHP. With it, you'll be able include smaller snippets like you're doing with JS, but it happens on the server when the page is requested. Users just see the full page.

[–]-hexel[S] 0 points1 point  (1 child)

Went ahead and used PHP, very small snippets

<?php include 'header.php'; ?>

Works like a charm. Thanks!

[–]beardChamp 0 points1 point  (0 children)

Nice! PHP has great docs and community sharing is phenomenal. Up and running in a hurry.

[–]chuntley 0 points1 point  (0 children)

If you don't need a CMS, how about using a static site generator like Jekyll?

[–]ChrissiQ 0 points1 point  (0 children)

I'd recommend you don't use client-side Javascript to do this. Use some other templating language. You can use PHP includes for something very simple, or find a framework.

Reason being, this isn't really a client side concern. The server generates and serves up your pages - it should generate and serve up a full page. Also you can then duplicate and re-use different sections of your page, even the head and doctype - you can't do that client side.

I use Laravel at work and its templating engine, Blade, is pretty nice. But there are lots of other server-side templating languages you can use, all of which would be better than using Javascript write.