What is a single page application and is this the technology I should use for developing my web application?
5th December 2011
My answer to What is a single page application and is this the technology I should use for developing my web application? on Quora
Single page applications are applications which are heavily dependent on JavaScript, with just one web page that you visit which then loads all other content using JavaScript. Prominent examples include Gmail and the new twitter.com
Instead of navigating to separate URLs these applications tend to update the fragment hash (the bit after the #)—which retains bookmarkability and allows the back/forward buttons to continue to function.
Personally I think they are a terrible idea for almost all sites and applications. They break one of the most important contracts on which the Web is based—the idea that I can perform an HTTP request to a server, request a specific path and get back a representation of the resource at that path. With single page apps I get the same representation for every resource—a nasty blob of JavaScript—and I’m expected to then fire up a full JavaScript+DOM implementation in order to execute and extract information from the resource.
They also break HTTP status codes—you don’t get a 404 for missing content any more, you get a 200 for everything.
Thankfully the HTML5 history API makes it possible to create sites/applications that don’t refresh the full page while still maintaining proper URLs. GitHub are a superb example of a site that does this—click around in the repository browser with JS turned on and it updates via ajax (and updates the URL bar as well)—visit the same pages with JS turned off and you still get the correct content.
Unfortunately the HTML5 history API isn’t available in IE until version 10.
My recommendation: don’t build something as a single page application unless you are sure you completely understand the implications of doing so. If you’re going to do it, you can avoid actively hurting the Web by implementing it using the HTML5 history API, ensuring everything works as it should without JavaScript and letting IE prior to v10 have the unenhanced version (the GitHub solution).
More recent articles
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024
- Three major LLM releases in 24 hours (plus weeknotes) - 10th April 2024
- Building files-to-prompt entirely using Claude 3 Opus - 8th April 2024
- Running OCR against PDFs and images directly in your browser - 30th March 2024
- llm cmd undo last git commit - a new plugin for LLM - 26th March 2024
- Building and testing C extensions for SQLite with ChatGPT Code Interpreter - 23rd March 2024
- Claude and ChatGPT for ad-hoc sidequests - 22nd March 2024
- Weeknotes: the aftermath of NICAR - 16th March 2024