-
Notifications
You must be signed in to change notification settings - Fork 125
Single Page App design with static files #3079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some questions:
If embedded HTML is the way to go, not a complete JSON overhaul, I can look into this. |
Definitely. I think it reduces or removes any ability to do JS in there.
I don't think so.
I don't think so. Just a little worse. |
CC @jcollins-g we talked about this design yesterday. |
Other similar options might be:
To be clear, I think the idea in #3384 is solid, and if we maintain the ability for the javascript navigation to be easy to disable, it wouldn't be hard for pub.dev to adopt. For pub.dev, we would probably prefer some variant of (3). <html>
<head>
<!--#include file="static/template_head.html" -->
</head>
<body>
<header><!--#include file="header.html" --></header>
<main><!--#include file="content.html" --></main>
<aside><!--#include file="sidebar_left.html" --></aside>
<aside><!--#include file="sidebar_right.html" --></aside>
<div><!--#include file="footer.html" --></div>
</body>
</html> (maybe having header and content on two files is overkill). But the point is that we would like to load the HTML, sanitize it and put it into a template we maintain. We could also do that with the SPA solution, if the javascript doing the client navigation is placed in a separate file, such that we can exclude it and concatenate the files serverside before serving to the user. Our new code path for serving dartdoc is here (we haven't migrated traffic to this code path yet):
The aim with this is to ensure that if the server running If the VM running Someday, this may enable us to run |
Why does the JS need to handle links destined for other pages? Is this an optimization? As discussed offline, I think this aligns well with Reducing dartdoc generated file footprint. The impacts of the two problems are multiplicative and dartdoc output could get quite small if we implement both of them. |
I need to correct that. I realized that's a bad design because it wouldn't support things like "Right click -> Copy link destination." and in implementing, it was easier to just make links point to the right place, statically, and every click is a full reload. |
It could be made to work. But it's a nin-trivial pain to do -- and testing it is difficult. Same with history management, it's also doable, just mildly painful. Serving plain HTML has a lot going for it. |
@srawlins I'm really impressed by the sidebars PR #3384, but it broke my docs (in version Clearly the Here's the code for the <div id="dartdoc-main-content" class="main-content" data-above-sidebar="burt_network/burt_network-library-sidebar.html" data-below-sidebar="burt_network/ProtoSocket-class-sidebar.html"> And here's the code for the <div id="dartdoc-main-content" class="main-content" data-above-sidebar="burt_network/ProtoSocket-class-sidebar.html" data-below-sidebar=""> When I edit the HTML to put the sidebar on the right as well, it loads... but only on the right side. My repository is here, feel free to ask for more info. |
Thanks for the report, @Levi-Lesches could you open an issue for what you're seeing? |
Filed #3467 |
Forgot to close this when I shipped it :D |
In order to solve output size issues (#2995), performance issues (#2799, #2998), and in order to enable some desired front-end features ([citation needed]), we can convert generated docs into a rough Single Page App design.
Typically a single page app would have a web server at the backend which is generating JSON responses to update the contents of the page, but we can carry out the minimum amount of work by just dumping slightly different HTML files, and incorporating some JS to request them and insert HTML snippets into the DOM.
Background
The long and short of our performance and output size problems come from this fact:
Design
In a green field design, we could re-imagine dartdoc to instead dump out one or many JSON files which would be served to a JS app and drawn into the page. But in this design, I take all of our existing code which generates one HTML file for every element, and make only small changes.
Generation
Today, for each element, we generate an HTML file with the following 5 sections in its body:
The blocks with incredible amounts of duplication are the two sidebars. The footer may also be perfectly duplicated across every file, but probably doesn't represent a lot of bytes.
In this design, for each element, we instead generate an HTML file with the following 2-3 filled sections:
The other sections will be present but empty (or near enough; there are some breadcrumbs for mobile at the top of some sidebars)
The HTML will look something like:
Additionally, we generate a few more files (apologies, #1272):
Initial page load
This new design requires that docs be served from an HTTP file server. The dartdoc package uses the dhttpd package in it's grinder scripts. Python's httpd module works fine as well. Whatever currently serves docs for pub.dev, api.dart.dev, and api.flutter.dev, will also work fine.
When a page is loaded initially, the browser will fill in the DOM just as it does today, except the sidebars will be empty. On load, some JS will read a data property of some tag (body?) for the left sidebar, build a URL for the HTML file for the desired sidebar, and request it. It then inserts the sidebar into its proper place in the DOM. The JS will do the same for the right sidebar.
Linking
As an optimization, to reduce page load (typical SPA optimization): we can add click handlers in the JS for all links destined for other pages within the same doc site.
When a link to another page in the same site is clicked (like a doc comment reference, or a type in a signature, or a member with a class, ...):
<header>
section with that of the response<main>
section with that of the response<title>
tag (other stuff in<head>
?)The text was updated successfully, but these errors were encountered: