
Build Static Websites - sfeng
https://eager.io/blog/build-static-websites/?hn
======
sanderjd
Absolutely, take static as far as you possibly can. In a world with S3 and
Cloudfront, there is really no reason for a static site to ever be down. This
is great for a company's marketing focused web presence. But often the reason
you're getting all those visitors to your site in the first place is that it
does something valuable that requires data persistence, which usually implies
user sessions, which implies authentication flows, and all of this requires
being able to serve _dynamic_ requests at scale, so you need to figure out how
to do that as well.

But we definitely serve too much of the web from dynamic php sites that could
easily just be HTML files sitting in a cache or on a file system.

~~~
sfeng
Just to take it a step further though, in a world where every browser can run
Javascript and make AJAX requests, which of your requirements can't be handled
by the client communicating with an API directly? Considering sessions for
example, local storage is supported by virtually every browser you can name:
[http://caniuse.com/#feat=namevalue-
storage](http://caniuse.com/#feat=namevalue-storage)

In my experience, it's significantly easier to scale an API than a traditional
(PHP-style) web server.

~~~
michaelmior
Why can't sessions be handled by by communicating with an API directly?

~~~
sfeng
Sorry if I was unclear, I was saying sessions _could_ be handled by
communicating directly with an API.

------
CJefferson
Static website generators seem to come and go -- would anyone like to comment
on one they like that seems to be lasting the test of time? The obvious one
seems to be jekyll (possibly with octopress on top of it), but I'm interested
in any others.

~~~
slimsag
I don't know about "lasting the test of time", but I recently used Hugo
(Jekyll clone written in Go) and found it impressive.

[http://gohugo.io/](http://gohugo.io/)

~~~
ethread
I've been using Hugo for a couple of months and I've been impressed with its
speed and ease of use. Here's a short post with my initial impressions:
[http://www.threadhunter.com/2014/12/hugo-static-website-
engi...](http://www.threadhunter.com/2014/12/hugo-static-website-engine/)

------
llama052
Working for a web firm that has a CMS, and web platform that is 95% ran from
SQL queries. Reading this reminds me how cluttered and loaded websites have
become. Granted I'm not a developer, but it's noticeable when you have to
account for 1.5 seconds of latency because of database pulls, and the fact
that it makes everything more complicated, as well as harder to design for
resiliency.

------
tenpoundhammer
I tried building a static website for people to browse tech article headlines
that were gather ed from around the web. The feedback was that people like the
style and general idea, but wanted a crap ton of features that can only be
accomplished in a highly dynamic and scalable web site. IE Logins, Voting,
Commenting, Friending, Favoriting, Etc and so forth.

~~~
tootie
A lot of that stuff can be done with embedded third-parties like Disqus or
ShareThis.

~~~
tenpoundhammer
That's totally true, but it's off-putting to farm out the core functionality
and it's underlying data to a third party.

------
talles
Static websites are great, I love them. I definitely _generate_ them when
possible.

But beware, if your website start to grow and becomes more dynamic, take a
step back and rethink if you should still go with all that _generation_. Could
be a pain in the future.

Someone correct if I'm wrong, but the people behind the The New York Times
website had to do a major rewriting of their code base due to that (I remember
seeing some presentation about it some time ago, but I can't find the link
nowadays...).

------
limeyy
Another solution we implemented was to have a WordPress site up, but only
serving a spidered copied HTML version of it in the public_html directory.

Every 2 minutes the site gets fully spidered, dumped into flat HTML files. And
if the dump is not successful, because of a database connection or any problem
at all, it doesn't get saved and doesn't overwrite the public_html dir.

~~~
sea6ear
This is interesting. Do the internal links get updated to point to the static
spidered version or do they still point to the dynamic website?

I've been toying with the idea of creating a product / service that would let
you choose which internal links went to the static copy and which would be
forwarded to the original site so that dynamic stuff like commenting could
still work (although perhaps display would be delayed), but everything else
could be static / cached.

Honestly I think a proof of concept could be done using something like wget to
mirror the site and a little ruby or awk to do the specific link rewriting.

------
iamdanfox
I've been trying this philosophy out on a little GitHub Pages editor app [1].
Everything happens client side apart from a tiny bit of OAuth handled by
heroku!

1:
[http://github.com/iamdanfox/ghupdate/](http://github.com/iamdanfox/ghupdate/)

------
sosuke
How do plugins like WP Super Cache [https://wordpress.org/plugins/wp-super-
cache/](https://wordpress.org/plugins/wp-super-cache/) compare with straight
HTML pages? The extra overhead is in the PHP serving up the cached HTML page,
but how effective is it in comparison? More of the static site development
setups don't have an admin system that compares with WP, is there a WP plugin
to export to a static site?

Edit: WP caching benchmarks [http://cd34.com/blog/scalability/wordpress-cache-
plugin-benc...](http://cd34.com/blog/scalability/wordpress-cache-plugin-
benchmarks/)

~~~
jeffreyrogers
> is there a WP plugin to export to a static site?

Here is one I found [1], I've never used it though, so I don't know how good
it is. I'm sure there are others as well. It would be nice if there were a
static site generator with an interface as nice as WP.

[1]:
[https://github.com/megumiteam/staticpress](https://github.com/megumiteam/staticpress)

~~~
ckluis
It would be nice if wordpress itself had the option of pressing a button
saying - push to static. When you make an edit -> update static files. This
would be fantastically easier + it would potentially mean 1/4 of the web gets
faster overnight.

~~~
sogen
+1

oh man, that's a great idea, that would grow WP adoption rate by 1000x

~~~
ckluis
It literally couldn’t grow that much. It can only go from 1/4 of the web to
4/4 of the web. :)

~~~
sogen
I Always give a 110%, maybe my math is wrong!

------
rakoo
I get that building static websites is interesting, if only because they're
easily backupable, deployable and are generally lightweight.

But if the problem is about resisting traffic, then that's the reason why CDNs
were invented: cloudflare is an example, and the seemingly unactive coralcdn
([http://www.coralcdn.org/](http://www.coralcdn.org/)), even simpler to
"install" and has a very interesting architecture (I encourage anyone
interested in P2P stuff to take a look at their papers).

Keeping your server behind some form of CDN also has the advantage that you
keep control over the actual storage of your data.

------
rikkus
I like the static site idea (I used it for years for my personal site), but I
also like having a web front end for editing. I can't find a static site
generator with a dynamic admin/posting end. Anyone seen one?

~~~
danielnaab
For many use-cases, [http://prose.io](http://prose.io) works well.

You can then use TravisCI (or the like) to trigger the site rebuild and
deployment.

~~~
rikkus
Ah yes I saw prose before and it looked promising. A bit techie for most, but
it's fine for me. I had wondered about build and deploy - thanks for the
pointer to TravisCI.

------
franzpeterfolz
If caching is setup properly, you won't need any Database-Querys unless your
Content changes.

A static site needs also to be served. HTML-files are on the Servers
Harddrive. They have to be read and send to the client.

A clever Caching-Strategy might beat this aproach by reading the files once
and Serving the content from memory. When I write "reading the files once",
this also includes making a db-query, rendering a HTML-Site and caching the
result in a Tool like memcache to serve it from there.

------
Kenji
I get the point he's making, but when I want to add something as simple as a
counter my website already stops being static. The question you have to ask
yourself: How many static websites are in your "favourite" folder? When I look
into it, I have a hard time finding a single one.

~~~
sfeng
Fortunately websites can run javascript now, allowing you to do virtually any
dynamic thing you need. Counters in particular are an interesting example,
because they were inserted as images into websites long before the idea of a
dynamic website was popularized.

You can see many of the things you can do just on the client in our apps list:
[https://eager.io/apps](https://eager.io/apps). We don't have a counter in
there yet, but it's certainly possible.

~~~
Kenji
I'm not sure if I don't understand or you don't understand. No, a counter
requires (at least) one integer of persistent memory. And if it's not on your
server it's on someone else's server. Bottom line, your site stops being
static.

------
shockzzz
Now all you need is the ability to host an open-source version of Firebase on
AWS and you're set.

------
michaelmior
"never has to be updated" Not sure what is meant by this.

~~~
sfeng
It's referring to system updates. The need to update your MySQL version, or
your Bash version when there's an new vulnerability. All the things you have
to do to keep a server on the internet secure and operational over time.

~~~
michaelmior
I assumed as much. But _someone_ still needs to do that for the server hosting
your static website. And for a dynamic site, you still have the option to
offload operational concerns to a third party.

------
RaffRaff
I'm running a discount for my design service today Somebody might find it
helpful, especially when you are focused on building websites, it saves you
time [https://gumroad.com/l/kxkNL](https://gumroad.com/l/kxkNL)

