Can we manually update a page on the CDN (i.e. with headless Chrome)?

So I’m delving a little bit into what Zeit is calling “Serverless Prerendering” (Introducing Serverless Pre-Rendering (SPR) – Vercel), and was wondering what might be achievable with Netlify. Ideally I was wondering about setting up a webhook that would be used whenever editors update something on the CMS. This webhook would run a lambda function leveraging headless chrome to prerender the edited page with new data and then update the CDN cache so that visitors would see the changes instantly without having wait for the site to be rebuilt. The main issue I see here is that I’m not sure we are able to programmatically update a single asset on the CDN like that.

Any thoughts?

1 Like

Hi @kmcaloon,

We do atomic deploys, you can’t send us only 1 file in that way, you have to send every file you want published with that deploy. However, we don’t re-upload a file that already exists on our origin. We do provide build-cache, which means theoretically if you had a static site generator that supports incremental builds, you could copy the files necessary to do those incremental builds in to the cache. Then restore them at the beginning of your next deploy and then run your incremental build process which will create just a single new changed file. All of those files will then be available to publish at the end of your build.

What we do at that point in the deploy process is get a SHA of all of the files you’re deploying and check if they already exist on our CDN origin. If they are already on our origin then they won’t be re-uploaded. Only that one new file would be uploaded and references are made in the deploy tree to point to the other files that already exist.

Most of the necessary pieces already exist, and there’s a community-supported library out there to help you use our build cache: cache-me-outside - npm

What’s mostly missing is an SSG with good support for incremental builds.

2 Likes

Got it thanks. Yea, I really think there is a huge need for Gatsby and others to push forward with incremental builds. I’ve never tried it, but React Static is supposed to support it as long as only data is being updated.

Hmm, so what about this. Repo for the site exists with 2 branches dedicated for deploys. One would be the master branch that would be used for full site generation. Another branch would be a dist branch that would contain the generated files after deploy – basically a replica of the files on the CDN. Then for “incremental” functionality, when editors update on the CMS, the CMS triggers a function that prerenders the new page on the server, pushes to thedist branch, which then triggers a new Netlify deployment which would just serve the files in the repo without having to rebuild bc everything will already be prerendered. Does that make sense? How would this work with the build cache since the “incremental” deploy would be from a different branch?

1 Like

Hi,

Sure, that would definitely be faster since you don’t have to run a build step, so we’ll just upload the changed files. You can set any branch to be your publish branch, so it wouldn’t be a problem to use a separate branch. I’m interested in seeing how that would work, please let us know!

1 Like