Hi Mikael,
The site is statically generated using Jekyll. This means we get static/persistent URLs, but for perf, decided to ajaxify the site so its bundle of common components only load once. This speeds things up quite a bit as you're navigating around. The difference is especially noticeable when viewing under a polyfill'd browser.
There's nothing special to injectPage() other than its interactions with custom elements.
The flow looks like this:
-
capture all link clicks. if they're a link, we pass the link's href to injectPage(). The href is the URl of the page we want to load.
- injectPage() makes an xhr request to the url and swaps in relevant meta data (the page title, header title, site-banner theme
- it also does a few other things like records
- analytics hit
- highlights the item in the left nav corresponding to the page
There's challenges to making this work:
- custom elements in an xhr'd document are not upgraded. This is why you see the use of setAttribute() instead of setting the element's property directly.
- inline scripts (any demos in the page) are not evaluated when using .innerHTML. This means we have to
manually do that ourselves.
- the history api `popstate` event is buggy in webkit. It erroneously fires on page load and which cause all kinds of pain.
BTW, if you're building a single page app, I'd recommend looking at combining core-animated-pages and core-scaffold instead. This is a much better flow for apps. The reason we didn't go that route in the first place was because those elements didn't exist!...and because we have a ton of pages (authored in .md for flexibility). SEO is important for a content-driven site.
Hope this helps,
Eric