7 ms·
I think what you say makes no sense at all. The idea of AJAX/SPA was to provide interactivity and a less technical UI that caters to the average Joe. AJAX/SPA
by elnygren 9y ago
I think what you say makes no sense at all.
The idea of AJAX/SPA was to provide interactivity and a less technical UI that caters to the average Joe. AJAX/SPA moves some of the computation from the backend to the frontend so the service scales better for millions of users.
This forum is not going to be fast for millions of users (it might not even be for hundreds of simultaneous users) because the server has to render everything again for everyone.
Server side rendering is good for response times, that's why the SPA world went back to it (Google: react ssr). SPA is good for scalability and average Joe UI.
...and AJAX is there so we don't need to do a full page reload all the time. Again, not because of response times.
- dullgiulio 9y agoIf it were to scale to millions of users, caching would help. At that point, you'd have to cache the JSON responses just the same, so the complexity of cache invalidation would be there in the exact same way. But you would still not have the additional load and bloat on the user browser.
- elnygren 9y agoYou are correct; caching is always hard. Load and bloat? Well that depends. If you're doing a realtime collaborative texteditor with a realtime chat, I just don't see how you'd get anything even remotely nice without what you call "load and bloat". However, to return to the original topic. Which is simpler: a) creating a performant data API b) creating a performant server that handles data stuff just like a) AND all the rendering & UI stuff Surely the latter is more complex since it has more responsibilities?
- combatentropy 9y ago> AJAX/SPA was to provide [...] a less technical UI I hadn't heard that reason before. Can you please talk more about this? > This forum is not going to be fast for millions of users (it might not even be for hundreds of simultaneous users) because the server has to render everything again for everyone. This theory doesn't match reality. In reality, multipage applications are faster than single-page ones. In fact, most things on the internet still are multipage, including web forums. Most web forums are powered by PHPBB, a multipage web app, and they were powered by PHPBB 15 years ago, when hardware and PHP were much slower. This very site is a multipage web app, and it holds up just fine, even though it has enough users to bring down other websites. Single-page applications seemed like they would be faster, but usually they aren't. First, let's look closer at a multipage application. All of the scripts, styles, and images should be cached after loading the first page, if you set the headers right (the Expires header, mainly). Therefore, what is left? The content. And I have found that the size of the HTML content is often close to the size of the same thing in JSON --- at least the way I write HTML (I try to keep it lean. Few classes, extraneous divs, etc.). This is because JSON has all those keys: { "color": "red" } while HTML has just the values: <div>red</div> That was a simple example, but I measured a bigger one, and the size turned out to be about the same, especially after compression. All of those HTML tags compress well, because of repetition. Now if they are the same size, then they should load in the same time. Except they don't. The server-rendered page loads faster. Why? Because of progressive rendering. When just some of the HTML has come down the pipe, the page appears. But with AJAX, all of the JSON must first load, then be parsed, then wrapped in a template, then inserted into the DOM. Then it appears all at once.
- elnygren 9y ago> Can you please talk more about this? Average Joes want spinners, buttons, draggable stuff, toggles etc. that don't lead to a page load everytime you press them. Sure, you can say that "well just make a multipage app with some jquery". But at some point you're just approaching a SPA with SSR support. Imagine facebook's chat but everytime you hit enter you had a full page reload :D > In reality, multipage applications are faster than single-page ones. I agree. They are faster for a single user when the usecase is a semi static page like a forum. However, the SPA + API model makes stuff easier for the backend side and allows that average Joe UI stuff. It scales well to millions of users. The thing is, it's not about you. It's about everyone. We want to build services that please the majority and backends that stay up when the majority is logged in. Also, it really isn't possible to build realtime/dynamic stuff with a "let's render some HTML on the server" mindset. How do you do realtime chat? Realtime games? How do you do a collaborative text editor? and so on. JSON/SPA/AJAX are not there to so your static forum page loads fast. They are there because of the next generation of the web.