Last active
August 29, 2015 14:21
-
-
Save mattLummus/84254eb81b9608a2da6d to your computer and use it in GitHub Desktop.
SPA Routing w/ Progressive Enhancement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A structural issue I've been thinking about a lot lately is routing in single page apps. | |
S.P.A.'s are great. They can increase speed (== UX++) and reduce the load on your server. | |
However, routing can be tricky and they can become a barrier to progressive enhancement. | |
1. How to set up your server side routing | |
Server can accept either hash uri's (/#/foo/bar) or hashless uri's (/foo/bar) | |
These should have the same result with the exception of the client not reloading the page when the hash is present | |
2. On an initial page load, serve pre-rendered html on the initial request. | |
The key here should be that all links are hashless - meaning, they will trigger a page reload. | |
If a user clicks a link, they will request another rendered page from the server. | |
3. If JS is enabled, after loading change all links to hash hrefs. | |
This effectively changes from a server rendered page to a client-rendered SPA when JS is enabled. | |
Possible improvements: | |
Cache the client IP server side and reroute requests to a seperate node responsible for rendering | |
Could also combine with knowledge not to send JS packets after first request to reduce load and latency. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment