davestewart / nuxt-content-assets

Enable locally-located assets in Nuxt Content
https://npmjs.com/package/nuxt-content-assets
108 stars 7 forks source link

Optimise content parsing watch #18

Open davestewart opened 1 year ago

davestewart commented 1 year ago

Background

When Nuxt Content starts, it scans, parses and caches all content, so documents are processed only once.

Nuxt Content Assets hooks into the "after parse" hook and transforms asset paths, just before the content is cached.

Nuxt Content only updates the cache when documents are:

However, because Nuxt Content skips cached content on some startups, Content Assets cannot be sure that all documents have had their relative image paths transformed.

Content Asset's rather brutal solution to solve the initial parse is to nuke the .nuxt/content-cache folder on each new build, which forces Content to re-parse and re-cache all content documents.

Whilst this is fine for smaller sites, it's possible that on larger sites and on Docus sites (see this bug) the lack of cache could be problematic (but to what degree I don't have data on)

Proposal

Rather than nuking the cache each time, the hook callback could be extracted to a standalone file, and applied to the cached files individually:

Live reload

Currently, not sure how to live-reload docs:

Notes

Aside from "doing the right thing" I don't know how much of a real world effect not nuking the cache will have.

Obviously, once the cache is deleted, updating image paths is fairly critical, but to what extent?

It should at least make Content startup quicker, as it will use the previously-cached values.

Before starting this work, we should research: