Go fast? Go Web native!
Send HTML and let the browser do the work
Aleth Gueguen explains how browsers turn HTML into visible content and recover from malformed markup. She contrasts that path with the work of parsing and executing JavaScript to turn JSON into DOM nodes, then introduces the multi-page application as a natural fit for HTML-first delivery.
One action per page, with the DOM as state
Gueguen maps common business tasks such as searching, sorting and entering data to individual pages with their own JavaScript. She shows how to reuse DOM nodes, delegate events to a parent element and keep page state in the DOM, using URL parameters or browser storage when data needs to carry over.
Serve pages from cache, even when only part fits
Gueguen describes testing offline on a boat with one solar panel and several days without a connection. She explains how a service worker can intercept navigation requests and serve cached HTML, and how her stitch-and-serve approach combines a cached header and footer with a dynamic HTML fragment.
Queue a form submission and preview a photo offline
Gueguen uses the Background Synchronization API and Workbox to explain how a short form submission can wait out a brief outage. For larger files and longer outages, she shows how storing a photo in Cache Storage under a URL gives the user an immediate preview through an ordinary image element.
A 250-input audit form in twelve days
Gueguen applies Gall’s Law to the tight delivery schedules she faces as a solo developer building business software. After polling the audience on HTML-first delivery and native APIs, she recounts shipping the first version of an energy audit application with roughly 250 inputs in twelve days.
Start with one page and track what you cache
Gueguen identifies forms, documentation and product pages as starting points for adopting HTML-first delivery. She walks through Workbox routing and precaching, including how its command-line output makes growth in cached assets visible. She closes by revisiting native HTML controls, DOM node reuse and server-rendered HTML.
Q&A on partial updates and browser-native offline support
Barry Pollard asks about declarative partial updates, and Gueguen describes how field workers retrieved large product documentation fragments while reusing cached page headers and footers. A second question prompts a discussion of a built-in browser offline mode, the flexibility of service workers and the need for wider implementation of their APIs.
Q&A on sessions and what clients are really asking for
Gueguen describes how her apps authenticate users before downloading assets and use cookie-based sessions for requests to the server. She then explains how asking clients to walk through their workflow can uncover the business problem behind a request for a particular button or checkbox.
Q&A on keeping the dependency list short
Gueguen describes using a few Workbox modules and a small library that adds promises to IndexedDB. She recalls making an exception for a client-side Excel export, and the host closes by recommending Jeremy Keith’s Going Offline.
Alet Gegha has been, testing out ideas about working offline on a boat. Really one of the better places I can imagine to do that. I'd much rather be on one myself. But, she has a long history of doing things offline and online and she's going to talk to us about some amazing things you can do with web native APIs.
Please welcome to the stage, Ella.
Hi. Hello, everybody. Okay. So my talk is go fast, go web native. So I just want to start a little bit from the beginning. So what is the best known language to the browser?
It's HTML. You know, a browser is a piece of software which is highly optimized to ingest HTML and show it to the browser, to the user as fast as possible. And one more thing, you can throw at it any HTML, even broken HTML. The browser will do anything it can to just show anything, content they have to show.
Try to do that with JavaScript and ship JavaScript with one missing semicolon. You know what the result is. So... Oh, sorry. Okay. My clicker does not... Okay. You can't beat HTML when you want to put pixel in the screen. There is no fastest way to do it.
Just so you know the difference between shipping HTML and shipping JSON with JavaScript. When you ship HTML, what the browser does... Okay. I'm not a professional browser developer, so bear with me and pardon for the... All the mistake I go...
I do. But basically, you you ship HTML, the browser pass the layout and just show it on the screen versus what the browser has to do, all the works the browser has to do if you ship JSON and JS. You have to pass the JS, execute it, build the HTML, insert it into the DOM, and now you can show it to the user. So you see the difference.
So yeah, if you want to go with HTML first, yeah, it's quite natural to do a multiple page application. So what I want to show you is how I do it, and have done... Been doing it for a long time. And the the things you have to understand is the kind of app I built is line of business app, like app where you do stuff with data versus app where you consume content.
So basically, when you have to do stuff with data, it's it's more like it's like you have to browse the data, filter it, sort it, search for it, maybe browse documentation and then enter data forms. And it's very easy to represent each action as one page.
And the advantage of that is the page is your model. And the JS you write for the page is just scoped to the page. So if you ship one page, you ship the least amount of JavaScript you need just to animate the page, less cost to write. And if you navigate from page to page, you will start from the clean state so you don't have all the problem of memory leaks, etcetera.
And I go with three additional rules. It's keeps the DOM. Do not rerender at any time. Just reuse the node. Rearrange the node. Insert them. Keep references to the node, and use the DOM API, which is if you have a huge number of methods to just do things with DOM and DOM.
Next step is delegate event, and I don't use any library to do that. The only thing I do is here when I have, for example, an input, but it would be it would be the time for a button, I have an attribute which says if there is a change on the input, do that thing.
For example, add a timestamp. And I listen to the top level element. So if we are in a form, I will listen on the form. If we are on another piece of content, I will listen to the top level element. And there is a very nice property on event handler.
It's a handle event which is triggered when the change handler is called. And then you can query the data sets with the event type which tells you, okay, you have to execute this function.
It's very simple. You don't have any library to do that. And then no state. The state is the DOM. But if you need to propagate a parameter, do it with query parameter. Well, be aware of sensitive data. Or it persists the data inside IndexedDB or local storage.
And that's it. As the three rules apply with MPA. So how about going faster? Well, skip the trip to the server. Go offline. So this is my r and d lab. So it's a perfect environment because you are very constrained with energy.
We have one solar panel. It's a 100 watts, which is not very much. And as soon as you get off the coast, like 20 kilometer off the coast, four g, five g is gone. You are on your own. So it's a very useful environment to test in real condition what's happened if you don't have network for like five days in a row. So cache page and serve them locally.
So remember, it's very useful when you have apps. We are real apps like Annie told us, doing things with data. So what you can do is check everything in the cache storage like audio asset, obviously, but also the HTML and the GS which controls the HTML. And you can't tell a service worker to, okay, if you see this URL, just serve it from the cache.
And that's all. You do a page navigation. The browser will query the page. The service worker will intercept the query and survey directly from the cache, sorry. Pardon my French. So good thing about service worker, from now you can see that I love service workers.
It's run on its own strength. That means it does not block the UI. You can make it do things which takes a long time. It will not block block the UI. It's very good. It acts as a router, as I say before. First slide. Just say to the service worker, if you see this URL, serve it from the cache.
No library needed. It gives you many strategy, you know, cache first, network first. We'll talk about that a little later. And it can be network failure resistant with no. No. It would be a little bit later. One strategy which is not very talked about is what I call...
It's not my... I didn't invent it. It's this and serve strategy. It's when you can't cache cache content because you don't need... You don't know it ahead of time, but you kind of know the structure of the page. Usually, you know, it's a header and the footer.
It doesn't change. So you cache it. But since you are doing it with a service worker, the service worker does not access to the DOM. It doesn't know the DOM node. So you can cut it anywhere you want. It does not matter, you know, it's kind of brutal. But you cache what you can't, which is fixed.
And then when you call the page, the service worker will call the server only for the dynamic content. And you can even say, okay, if you see this content and it's not cached already, just cache it. And all the call return HTML. So you just have to stick all the HTML towards...
Together and serve the page. It's very effective. It does not need much code, and it's fast, really. I've used it for a few apps, and it's super super simple to do it. You can be a little more fancy and use streaming, but I don't see really the point.
You know, maybe if you have really, really big, big, big content, it would be interesting, but just to serve documentation, product page, I don't see the interest. So, yes, what about being network failure resistant when you submit a form? Well, have an API for that.
It's called background synchronization API. So let's say you have a user, she submits some order and that's too bad. She's online. Well, no worry. The app registers a sync request, and the browser will detect when you go back online.
And the service worker will will be alerted and handle the sync. It works very well if the case is simple, like a very short form and the network failure is transient. You don't have to wait a few hours. And you have a very convenient library which is called Workbox, and it's a one liner.
Basically, they have a module specified for that, and they handle the fallback for the browser which does not implement background synchronization because at the moment only Chrome implements that. Now the case of photo and file.
When you have professional mobile web app, it's kind of mandatory to be able to take photo. But photo are big, you know, and it's binary. And if the network is down for a long time, you don't want to to the upload being handled by the background API.
So this slide is a tribute to Alex who one day pointed me that if you have file, you can store them in the cache storage, and it changed everything. So let's say you have a user. She picked a photo, and now you just say, okay, I'm build a response with a file and a request with an URL, and you put that in the cache.
Now your photo has a URL. Right? So you want to give a preview to your user. So you have an image element and all you have to do is put the source property to your URL and you insert it into DOM. The browser will ask for the photo.
The service worker will catch the query and serve it directly from the cache. No spinning up a reader or building blah blah blah URL, data URL objects, blah blah blah blah blah. No. Very simple. Thank you, Alex.
So this is the main recipe to go fast. Just break your application that you have one page means one action. Okay. The reverse. One action is one page. Just three rules. No library, none of these things. It's very easy to use.
Search page locally whenever you can. And you know there are a lot of page which can't serve locally like static pages, forms, anything. At least serve some part locally. And let your users submit form even if the network is down. So let's wait and think a minute.
You kind of see what I'm... Where I'm heading here is simplicity. Don't overthink things. Do things a simple way. There are even a law for that. It's law. Pardon my French. A complex system that works is invariably found to have evolved from a simple system that worked.
Just focus on simple system. So like I said, I build software for small companies and software for line of business software. And by the time company leaders contract with me, they have been needing the tool like for two months before.
And the next best time for the tool to be in production is for the next three to six months. So I don't have any room for experimentation. I really need to be sure that I will be able to ship in very few amount of time. It must be up in production.
For them, the money on the table is their money. So I really need simple and reliable take because I want to sleep at night. I want don't want to, you know, be bothered by, okay, is it right or is it wrong or maybe I didn't use the right tech. No. I use a very simple tech.
So I'm a one person team. I do everything EMPA with native app. I I don't use a network... A framework. I don't use a build. Can you do it with a bigger team? Let's find out. What would you do if you were to go with simplicity? So some questions.
How do you feel about serving HTML first? So your hands up for, yes, I want. It's very interesting. Great. Okay. Your hands were, maybe, maybe not, not sure. Okay. And your hand...
No, never, never ever. Okay. Nice. And second question, how much do you feel tempted about this using native web API? So hands up for, yeah, yeah, I want, I want, I want. Wow, great. Hands up for, maybe, maybe not, not sure.
Okay. Hope I will try to convince you. And hands up for, well, no, not interested. Oh, you're so nice. Thank you. So if you start with HTML first, how fast can you ship a fast app? This is hard data.
This is a project I did like two years ago. So the app is just a gigantic form like 250 input with cascading option, blah blah blah. And the brief was make it fast enough because if I have to wait for the next page, I will break the screen because I'm going to tap too hard on the screen because the button is not responsive enough.
And the and the app is used like you do a data entry for a whole day, two days in a row because it's for energy consumption audit. So it's really important. And I shipped and they had a deadline, obviously, and I shipped the first version in twelve days just using what I told told you, MPA. Kind of makes a point.
Yeah? Maybe? Okay. Let's try about what would be a potential first step if you would transition to MPI with HTML first rendered.
Well, find the page where constructing HTML from JSON and JS is overkill. Like I said, good candidate would be static pages, forms, obviously, documentation, product page where you could use stitch and serve strategy, Cache your asset, obviously.
Even all the GAs that control the page. And for that you have a good library which is Workbox. Who is using Workbox? So use it. It's very good at managing the list of file in cache. You know, it's a thing that it's just boring to do is constructing the the list of file you need to cache.
Workbox with watch all the file you need to add to your to your cache. It has a good set of predefined cache strategy, like cache first, stay while revalidated cache only, blah blah blah. It has a good module to do routing. So you can tell, okay, if this URL URL looks like that, go fetch this page.
If this URL looks like other things, go fetch in some other part of the cache cache. And it has a module for background sync. I would advise you to only use background sync only if it's a very simple submitter form while the network is down for a few minutes. If you have to handle, you know, a long term offline and then synchronization, do your own thing, using background sync from Workbox for this case is not very useful.
Okay. And it's quite simple to use. You have one config file where you basically say, okay, this is all the directory where you have to look for new files. You can even tell it the templated URL, say, okay, I have this page. It looks like that.
We have a template. When you when you do your thing, just route it on the on the good file, on the right file. And you have here on your service worker, you just use this construction work box pre caching pre caching route.
And you have a CLI where this this expression will be expanded to the whole list of file with a version. You will manage, you know, the cache and deletion. And the CLI has a very useful output. It tells you how many URL you are caching and the total weight here. So you can monitor over time, over your development, how much this number increase.
And you see, and it's very interesting because if you add a new library and the library is quite big, this number is going to jump. And it's kind of, do I really need this library? Do I really need to pay the price? Okay. Let's go a step further.
What can you do more? Like, can you replace JS power interactive element with modern HTML element. You know all the dialogue, popover, I don't know, details. Maybe it's a time to test it a little back and say, okay. Maybe I can just ship HTML.
And then you could look for page where you can use native DOM API instead of rerendering, I don't know, a list of task. You can reuse node. It's very effective. Like, you ship some list of nodes and you make reference on them, and then you can move them around.
It's go... It's really effective and fast. So what makes things fast in a web app? Well, it's very... The most effective way is just sending HTML directly from the server. I'm not sure, contrary to what said, Amy, that there is a big difference between server side generated site and server side rendered HTML where the HTML is constructed at the request time because server are fast, really fast.
Use service worker to serve page. It's quite... Once you get the mental model of using service worker is kind of natural. Okay. You set up the thing, you say, watch this list of files and do your thing, and it works.
And, yes, use native web API. It's the best simple system to ship fast and keep a fast product. So this is the end because I don't like to talk too much and I prefer to answer questions.
So Jason, your turn. Thank you.
Alright. Thank you very much, Aladd. Please come sit. I'm gonna open this doc and hope that a whole bunch of questions have magically appeared. And they did. You folks are wonderful. Which is good because I have a lot of questions. Great. But, it shouldn't just be ones coming from me.
And and I'm happy to see Jeremy here because I I know that he meant to be here for this talk because this is very near and dear to his heart. So, let's let's get to it. Barry, Barry Pollard down here in front from http archive and Google. Have you looked at declarative partial updates for your partial updates?
That was a bit that I'm really curious about. The stitch and serve.
Yeah.
That, like, talk a little bit about more of that, more about that because I think that's, it reminds me of things that Drupal does with cache tags and cache tag invalidation for parts of a page. Yeah. And I think that's really fascinating to do that without an underlying system.
Yeah. Well, can you elaborate a little bit of what you need to
want to So to come back to to Barry's question, is what if you, with the stitch and serve declarative partial updates, is that a thing that you have incorporated into your work or is this Yeah. Okay. Yeah. It's very effective. And and so are there some demos, things like that that people can can look at?
Not because it was client work. The use case was, for professional web app where the field worker needed to have documentation on product, well, product like big pipes, and they need a product documentation at the time where they are setting the pipes down the earth.
And so they have this long list of documentation, but you cannot cache everything because it's too big. So they just query the page and the footer and the header is cache. And I just just server... You... The query just ask the server for the dynamic part.
And so it's only HTML. And it can be a really big HTML. It doesn't change. It goes very fast. Does it answer your question?
Native web platform APIs. Yay.
Yeah. Allow
you to do that a lot easier than than right on manually stitching. And check it out. I'll talk to you afterwards.
Oh, yes.
And Sure. Just to make sure that people in the livestream hear that what Barry is mentioning is that what he was referencing is a web native API way of doing this, what you were talking about. Yeah. Great. I'm sure he's going post some things on blue sky, maybe some links, things to check out. You've got your homework, Barry.
You asked for that. Okay. We had another question from Tim Verik about, would you, do you think that this is something that really, should be supported in the browser natively or do you think service workers are the right place to manage this kind of workflow? Like should there be a just enable offline equals true?
Good question. If I were me, I would say yes because I think that the web should work offline. But... Well, it would be nice. Would be easier, yeah, I think, for developer to not have to think about service worker because service worker are a very low level API. This is why I told you use Workbox library because it abstract away all the boilerplate.
So I don't know because the good thing about service worker being a low level API is you can do a lot of differencing which would have no interest of being native in the browser, I guess.
I have to admit, I... I'm I'm not sure that I think it's a good idea.
I'm I'm... So
well, I'm curious if this actually will come from Jeremy later. Years ago, I saw him give a talk about pace layers and just sort of the the different layers of pace at which things change and evolve. Mhmm. And you know, TCP IP being very slow to JavaScript being very fast. And browsers are somewhere in the middle and it's great to have a universal support for something but they, let's be honest, they never do it exactly the same way and so that's the thing that would worry me about implementations of this Yeah.
Yeah. Versus service workers being a little bit more independent
Yes. Of Absolutely. You're absolutely right at this point. I think service worker are doing a very good job and we should try to fight to have more implementation of certain API of the service worker in every browsers.
I think that's about as far as we're going to get today. Okay. We had another question from Slava. Can you recommend some off technologies or hints for service worker related apps? I'm assuming this is about incorporating authentication. Was that the root of the question? I'm not sure if the questioner is here somewhere.
Yes. Is it about authentication?
Yes. Okay.
You're doing a MPA, multiple play... Page application, it's just a matter of login, having a login and being authenticated with whatever cookie, g w t, anything. What would be your use case?
Well, let's let's look maybe tie it back to one of your projects where I'm I'm assuming that for these... The software that you develop that you would want someone to be authenticated in order to be working with And with the and so what what is your go to for incorporating that? How do you manage authentication and that persistency of that across a session?
Yes. Like I said, basic login and with the app work with the back end. And so all the all the requests, the post requests are authenticated. This is an important part. So you have to be authenticated to have all the your assets downloaded and cached. Then you install the app.
This is important because there are some API which only work when the app is installed. And all the dialogue with the server is done being authenticated. So, basically, you just incorporate a cookie. I... Of the time, I use cookie because it's kind of easy to do and secure if you set up your cookie HTTPS only, secure only, same domain, and...
I don't know. There are three things to do, but it's sufficiently secure. I don't do anything very fancy because I don't see the point. Maybe I'm wrong.
Well, I think it's always a good policy to do something as simple as possible Yeah. Until it's too simple.
Yes.
We had another, great question. And this is, I think, Roderick, you asked the question for all of us. How exactly do I convince our management to allow us to test a website in the middle of the ocean for a few days?
Well, that's a good question.
It's it's one to ponder, but I I had to include that one. I wanted to make sure we didn't run out of time. Svetlana Stoichev Stoichev had a question. And I'm curious just with your business, you get to make these calls. If the customer is always right and they absolutely positively have to have some fancy Javascript thing because that's what they want to support, what do you say to that?
Well, my customer does not have this kind of question. I work, as I said, with small company. They don't have dev tech teams. They don't care about tech. They only know that they need a software tool.
They know a software will solve a problem they have. But basically they say... They go to me, say, this is a problem I have. This is the form of the response. Take care of it. I don't want to worry about it anymore. They don't care about JavaScript. It's not their problem.
They just want an app will be... That the app will be in production at a given time and that the app will do what they need. They don't care about anything else. I'm very lucky.
I I think that is a good reminder though that, I mean, so I I work at an e commerce company that is a whole React factory. That's another tale. But, I think one of the things that we see all the time and and I I think it's sort of you hinted at this is, what we if if the person asking that question about that feature is focused on an outcome, it's either there's this this bell or this whistle that I want for this interaction, this is the thing that I know so that's what I'm asking for.
But what they're asking for isn't, is to solve a problem. They want something to be engaging. They want it to function. They want it to do a thing. Yeah. And and we all too often hear that as the solution that is required rather than an investigation we should undertake.
You're absolutely right. Know, I I don't know why our brain are wired this way, but, yes, a client will arrive and say, okay, we need this button or this checkbox or whatever. And at first I say, okay, yes.
But then now I say, oh, yes, you're right. Now tell me the story. Tell me what you're trying to do. Tell me the business case about having this checkbox. And then sometimes, most of the time, okay, I'm going explain the business case. It's not that clear. Let me go back some steps before, and then the whole story unfold. And then you say, okay.
This is not a checkbox you need. Let me think about the bigger the bigger picture.
That's great. Thank you. So
say yes, but say yes, but tell me the story.
Well, that I I hope is going to come up in Stephanie's talk later about this being more of a design opportunity to think about solving performance in a unique and different way. But one more question before we take a break for for some coffee. Mick was asking if Workbox is the only library that you use or are there other other tools that you go to to help manage some of the service worker and and...
Oh. For service worker, yes. It's only Workbox and a very small part of Workbox. Workbox has a lot of different modules. I only use three or four. And I use a very small library to abstract... Well, no, it's not the same abstract. Okay. IndexedDB is a very old API, and you use it with callback and kind of boring.
And this is... There is a very small library written by Jake which gives you promises, so you can work with promises when you are using index d b. This is some... On all my projects, I have these two libraries, and then it's a really by project thing.
And I kind of try to not include too much library and just extract the bit I need. From one of my project, the app needed to export an excel, and I couldn't do it from the server. And I had to include this huge library just to speed out an excel file. Oh my god.
Well, those those are problems we can all relate to. Okay. So, one last plug is in addition to this to help you get started if you haven't done more with service workers, Jeremy has made his book going offline available online.
Very, very, very good.
It's a really worthwhile resource. I've learned a ton from it. Thank you for that, sir. And, thank you, Elette, for a wonderful talk. We learned a And
if you wanna talk, ask me question, I'm here.
Okay, folks. We are ready for a coffee break. Thank you, Alab.
People
- Barry Pollard
Technologies & Tools
- JavaScript
- handleEvent()
- HTMLElement.dataset
- localStorage
- CacheStorage
- Workbox
- Workbox CLI
- <dialog>
- Popover API
- <details>
- HTTP cookies
Standards & Specs
- HTML
- JSON
- DOM
- IndexedDB
- Service Worker API
- Background Synchronization API
- Declarative Partial Updates
- JSON Web Token
- HTTPS
Concepts & Methods
- Multi-page application
- Event delegation
- Cache first
- Network first
- Stitch and serve
- Gall’s Law
- Stale-while-revalidate
- Cache only
- Static site generation
- Server-side rendering
- Pace layering
Organisations & Products
- Google Chrome
- HTTP Archive
- Drupal
- Microsoft Excel
Works
- Going Offline













