Ask HN: How does HN preserve state so well?

6 points by preciousoo ↗ HN
I'm a bad tab hoarder and I have >500 tabs in my backlog, across many devices. One thing I've notices is that if I open an article from HN, if the <Back> button leads back to the HN homepage, it preserves the state exactly where I left HN opened at.

Maybe I haven't been on the static web in too long, but my memory is of pages refreshing whenever you hit back after some amount of time. Do they have a longer cache option? I don't see anything in their JS that suggests saving state.

3 comments

[ 2.6 ms ] story [ 19.9 ms ] thread
The HN DOM is a testament to a bygone era. Remember when the web wasn't flooded with tutorials and you had to reverse engineer other people's work to learn new things?
I think that's just how pages are when you write them in plain-enough HTML and aren't overwriting the DOM with JS all the time. The web browser keeps track of your scroll progress and has the page in its cache (like frankjr said). You can disable JS altogether and it'll work the same.

It's a modern anomaly with JS frameworks that we've hacked and over-stretched the DOM so far past its original design that basic things like going forward/back need explicit JS handlers that rarely work all that well. You shouldn't need any state in JS to store basic navigation. It didn't used to be that way, and arguably shouldn't be that way for simple text-based sites like this. Maybe it's just becoming a lost art these days =/