HACKER Q&A
📣 amichail

Why doesn't reload ask the web site to simulate a reload if it can?


So basically web sites would need to support a "simulate reload" feature.

Whenever the web site can simulate a reload, then it would be very fast (e.g., it would refresh the data shown without reloading everything else).

Whenever it can't or the user clicks reload again, the normal reload would happen.


  👤 dtagames Accepted Answer ✓
Websites that are setup like SPAs (single page apps) can do this. It's just something that has to be built-in to the app, not the browser.

A single page app can refresh or redraw just the portion of the screen that has changed -- and they can do it without even calling the server. This definitely makes web apps feel "zippier" and more like desktop apps.

If looking for new data from a server, a single page app can redraw just the portion of the screen where the data on the server is different from what's already drawn, and this also improves responsiveness.

Here's some more about SPAs in general [0] and an article I wrote about developing with web components [1] which is a modern way to build them:

[0] https://en.wikipedia.org/wiki/Single-page_application

[1] https://medium.com/gitconnected/getting-started-with-web-com...


👤 Comevius
If the question is why a reload is not allowed to be handled by JavaScript, so you can fetch updates, the answer is that it's not mean to be a regular navigation event, but a hard reset that unloads the document and it's resources.

Some users use it to fetch updates even when they don't have to, but they still get what they want. A site that automatically fetches updates can be unreliable, so you reload it, which also let's you check your internet connection and the server. If reload would be handled by JavaScript you would have to close the browser and open it again to be sure.


👤 gregjor
1. HTTP, by definition, works as a stateless request/response protocol. Distinguishing between reload (re-requesting the current page) and "simulated reload" requires maintaining state.

Browser caching can violate the stateless nature of HTTP, if the web site allows it to, but the user can still force-reload to bypass caching.

2. The user controls their browsing. Web apps that hijack navigation, history, or reloading take control away from the user.

In any case service workers can already do this, as another commenter mentioned.


👤 beardyw
A Service Worker can do just that. It is a script which sits between the web page and the server and can intercept requests from the page and responses from the server. It can cache responses and serve from cache if it wishes to. So a refresh can result in merely accessing cache. It also supports messaging to and from the page.

Having been put in place it's script is fetched once a day to look for changes.

It is a very powerful concept and widely supported I believe.


👤 PaulHoule
Just reloading usually uses the cache and is pretty quick. Shift-reload really reloads everything.