News for hackers. Stuff that matters.
Re:Why I Tend Not to Use Content Negotiation by dasmith91 on Sunday November 19, 2023 @10:41PM (#38342005)
Front-End Developers
Re:Why I Tend Not to Use Content Negotiation by quectophoton on Sunday November 19, 2023 @11:38PM (#38342320)
Also that's why single page applications are no longer technically single page.

    https://example.com/#!/
    https://example.com/#!/about/
    https://example.com/#!/users/
Are all the same page as far as the browser concerns, and if you move from `/#!/` to `/#!/users/`, and reload the page, you still load the same page (i.e. `/`).

But that was too ugly for URLs, so modern websites now use browser history APIs just so they can remove 3 characters from the URL and do stuff like:

    https://example.com/
    https://example.com/about/
    https://example.com/users/
Sure, if you load `/` and move to `/about/` you don't load a new page because of browser history APIs; but if you then refresh, now you load a different, uncached page (`/about/`, instead of `/`) even if the HTML in the response is exactly the same as in `/`.

Sure, the difference is not much, but to me it still seems like a waste when the response could have been cached already like in the first example.

Re:Why I Tend Not to Use Content Negotiation by alex_smart on Monday November 20, 2023 @12:32AM (#38342792)
> But that was too ugly for URLs, so modern websites now use browser history APIs just so they can remove 3 characters from the URL and do stuff like

Would back/forward buttons continue to work if we decided not use browser history APIs?

Re:Why I Tend Not to Use Content Negotiation by quectophoton on Monday November 20, 2023 @01:14AM (#38343248)
Yes, and a quick test with Mithril.js confirms it.

I could try with something like React, but that's too much for a quick test.

Re:Why I Tend Not to Use Content Negotiation by mewpmewp2 on Monday November 20, 2023 @07:21AM (#38346959)
Mithril.js also probably uses the history API?

.replaceState() will replace current url without putting it in the history, so back won't work, while .pushState() does.

Re:Why I Tend Not to Use Content Negotiation by PH95VuimJjqBqy on Monday November 20, 2023 @02:59PM (#38353677)
The other poster is wrong, the entire reason the history API exists is specifically because when these SPA frameworks first came onto the scene one of the things that was broken was history.

So they invented the history API's so SPA's could stop breaking some of the user expectations they were breaking.

Re:Why I Tend Not to Use Content Negotiation by prewk on Monday November 20, 2023 @02:01AM (#38343672)
The first one always requests / from the server when landed on/refreshed. The other one does not. This fact can be acted upon.
Re:Why I Tend Not to Use Content Negotiation by cylemons on Monday November 20, 2023 @03:30AM (#38344680)
What does the ! symbol do in url fragments?
Re:Why I Tend Not to Use Content Negotiation by scq on Monday November 20, 2023 @06:13AM (#38346346)
It was part of a scheme to make SPAs indexable by search engines. Google deprecated it back in 2015, as Googlebot can now execute JS.

https://developers.google.com/search/blog/2009/10/proposal-f...

Re:Why I Tend Not to Use Content Negotiation by vhcr on Monday November 20, 2023 @07:49AM (#38347220)
That issue can be solved with service workers.
Re:Why I Tend Not to Use Content Negotiation by account42 on Monday November 20, 2023 @11:28AM (#38350096)
The real reason for moving (back) from fragment URLs to real URLs is because the latter can serve different content on the initial load - specifically, they can act as actual webpages that use javascipt for progressive enhancement but work immediately whereas your / needs to display a spinner while you send of additional network requests to retrieve the content and build the page.