Generate file permalink without reloading the page
Problem to solve
When I am viewing a file and want to generate a permalink, and I use the y shortcut, the whole page is reloaded. This is slow. Why can't the URL in the browser simply be updated immediately since the page content doesn't really need to change?
Further details
This is already a feature of GitHub is a definitely nice polish
Proposal
Switch to permalink without reloading the page
Implementation Details
Phase 1
For this issue, we'll cover two new behaviors (both in service of the no-reload permalink feature):
- We change the behavior of the permalink navigation code to use
history.pushStateto update the URL (and the associated history item) to the permalink URL. - We add an additional piece of small code to update the title to include the SHA instead of the branch name.
Phase 2
In a later iteration, we'll:
- Bind a
popStatelistener when the permalink is triggered, so that the browser back button will properly unset the SHA from the window title, and potentially other reverting behavior, too.
Phase 3
In potentially the final iteration (see below), we'll:
- Update the entire page with the permalink SHA. There are a lot of discrete URLs scattered throughout the page that need to be updated (and reverted, assuming the back button is pressed) and there's no clear way to do that all at once. This update may require some exploratory work to figure out the best (most future-friendly, least intrusive, etc.) way to scan the whole page and update all of the links.
Future iterations
- Handle pressing the back button
- Change page title back to the branch name
- Change URL back to the non-permalink
- The selected ref dropdown changes to the commit of the permalink
- Some file header buttons become disabled
- Some repo-level buttons change their URL structure to adapt to the permalink
Links / reference
Edited by Thomas Randolph
