share
Stack OverflowWhat's the best platform for a static-website?
[+13] [9] Earlz
[2010-03-15 20:46:26]
[ html language-agnostic dry ]
[ http://stackoverflow.com/questions/2450365/whats-the-best-platform-for-a-static-website ] [DELETED]

I am building a static-website (as in, to change a page, we change the HTML and there is no DB or anything). Well, it will have a number of pages and I don't want to copy and paste the HTML navigation and layout code around everywhere.

So what would be the best platform to use in this situation so I can have all my layout and "common" HTML markup all in one place?

[+6] [2010-03-15 20:47:33] Dustin Laine

You can just use HTML and add server side include [1] files. Most servers support this, and both Apache and IIS are capable.

I just use ASP.NET MVC because I love it, but PHP would also work depending on your desired platform.

[1] http://en.wikipedia.org/wiki/Server_Side_Includes

Our platform is not completely decided. I personally like PHP. I know ASP.Net Webforms, but not MVC. I feel like MVC would be overkill for this, and we will be doing some javascript things, which is where Webforms starts to really suck. - Earlz
just make sure to check with your hosting provider... - Paulo Santos
Right now our hosting supports all 3, so it's not a problem.. - Earlz
MVC is simple and provides nice features and clean markup. - Dustin Laine
+1 for good ol' SSIs. - maerics
1
[+3] [2010-03-15 21:17:30] Josh Pinter [ACCEPTED]

I'll throw down a vote for PHP just because of its simplicity for small requirements like this. If you are hosting on a cloud or a managed environment then they most likely will have the required php backend setup and all you need to do is:

  1. change the extensions of all your pages from .html to .php

  2. create template files named something like header.php and put them in an /includes/ directory. Inside these 'template' files can be your html for various re-used sections of your site.

  3. call these files with <?php include_once 'includes/header.php' ?>

Easy-peezie lemon-squeezie.

If you want something more complex and structured, one of these other answers is more appropriate.

Josh


I accepted your answer because it's the most specific for what I'm doing.. but I also built a middle step so that I can "build" all the PHP pages into HTML and then just deploy the HTML - Earlz
I've never done it like that before but if it truly is static than html would be best for the end product. Another small bonus of using php is that you can easily generate simple dynamical content such as updating the copyright year: Copyright Earlz (c) 2009 - <?php echo date('Y') ?> But it sounds like you know what you're doing :) - Josh Pinter
@Earlz: Am looking for a very simple static website generator like this. Never done any php, how would one actually do your middle step, that is generate the static file? - Richard H
@Richard the easiest way is just to view the PHP page in firefox and "save file as" - Earlz
2
[+2] [2010-03-15 20:52:15] Quentin

I've been using Template Toolkit [1] for this, specifically the ttree utility [2].

There are no server dependencies (because all the combining of files happens at build time, not run time) and that makes is trivial to configure the server for good cache control and compression options.

[1] http://template-toolkit.org/
[2] http://template-toolkit.org/docs/tools/ttree.html

3
[+2] [2010-03-15 20:54:05] Max Shawabkeh

Well, there are a few ways to do it:

  1. Simply use frames. It's an old and somewhat clunky technique, but it is probably the fastest for the server side.
  2. Use server side includes [1]. Very efficient but somewhat ugly and you won't be able to upgrade it if you ever decide to add more flexibility.
  3. Use a scripting language like PHP and its native include()/require() functions to include the headers. Might be a tiny little bit less efficient, but you won't really be able to feel it, and if you decide to make it more dynamic in the future, it'll be easier to upgrade.
  4. Have a single main handler page with all the persistent navigation and whatnot, then include your content pages, while doing an internal URL rewrite behind the scenes. This is probably the least efficient of the four, but the margin is too low to notice, and unless you need your content pages to add something into the <head>, it's also the cleanest.
[1] http://en.wikipedia.org/wiki/Server_Side_Includes

(9) ewww.... frames - Earlz
"unless you need your content pages to add something into the <head>"? Like a title?! - Quentin
@Earlz: They're there for the sake of completeness. @David: I was more referring to something like arbitrary code, scripts/styles/meta tags, where it'd get unnecessary complex without a db. Preset stuff like titles can be easily arranged though. - Max Shawabkeh
4
[+2] [2010-03-15 21:11:13] Paul Fisher

Jekyll [1] is a newish static site generator written in Ruby. It's popular among the Ruby/GitHub–type crowd, and at least one person I know uses it for his own websites. It seems pretty nice.

You could also look at Hyde [2] (I kid you not), which is essentially the same thing but in Python with Django, so you can use Django features to generate your content.

[1] http://jekyllrb.com/
[2] http://ringce.com/hyde

I lol'd at the Jekyll and Hyde bit.. - Earlz
(1) There's also DocPad for the Node.js/CoffeeScript crowd, which is very similar but supports thew node.js markups like coffeescript, coffeekup, jade, and stylus - among with other features like support for dynamic pages out of the box. - balupton
5
[+1] [2011-08-12 05:21:27] Max

I was in a similar position to you. I tried all sorts of static site generators. I settled on Middleman [1]. It's easy to use, and I like that it is very similar in layout design to Ruby on Rails.

[1] http://middlemanapp.com

6
[0] [2010-03-15 21:05:42] jpartogi

I choose django for this kind of work. Its features like:

  • direct_to_template [1] is useful to render the template directly and if I want to have full-control with the template
  • or flatpages [2], is useful if I want to administer the content of the static page, like a CMS, from its built-in admin system [3]

Besides those features that IMO fits in your requirement, django is also unobstrusive and very lean. It's fairly easy to get started, especially if your requirement is only for static pages.

But this is if you have the luxury to have Python as your platform. Otherwise as others have suggested, PHP might be a better fit.

[1] https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-simple-direct-to-template
[2] https://docs.djangoproject.com/en/1.4/ref/contrib/flatpages/
[3] https://docs.djangoproject.com/en/1.4/ref/contrib/admin/

7
[0] [2011-04-21 01:38:06] Pushpendra

If it;s just a bunch of static pages you dont need ASP.net or PHP , just plain HTML is good enough !


...No it's not. What if you need to have common-code between multiple pages? Copy-and-Paste is not a solution. Ever. - Earlz
8
[-1] [2010-03-15 21:39:19] Marcel

You may want to look at TiddlyWiki [1], a CMS contained in a single html file.

[1] http://tiddlywiki.org/wiki/TiddlyWiki

I love tiddly, but it doesn't belong on the web as an actual website IMO. Plus, very hard to really customize.. - Earlz
9