-
Notifications
You must be signed in to change notification settings - Fork 0
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
Invalidation strategy #1
Comments
Thinking about it, I can leave the implementation up to the developer. It should simply be a parameter when calling InlineCacher, e.g. new InlineCacher({
cachebust: "foo",
}); On the server: if (cookie['inline-cacher'] === 'foo') {
// whatever
// maybe 'foo' is a hash and we can compare the hash of our latest styles.
// maybe 'foo' is an expiration date and we can check the time.
} It's up to the developer to use the value of This does, however, assume only one block of inline css. It provides a hook for the server to clear the inline-cache if needed, but it doesn't answer the following two scenarios:
Ideally these should all be both independently cacheable and independently cache-bustable. |
Think the Each identifier could be associated with the time it was set. We would serialise this as JSON. That way the identifier doesn't have to be a hash, it can be an id, and we would look at the time it was set to figure out if we should invalidate the CSS and send a new block down. Every request the browser sends would contain the serialised cookie, which would look something like Example implementationHTML: <script src="inline-cacher.min.js"></script>
<style data-inline-cacher="abc123">
foo { ... }
bar { ... }
</style> Server requests: // pseudocode
$inlineCacher = JSON.parse($_COOKIE["inline-cacher"]) || {};
if ($inlineCacher['abc123'] && $inlineCacher['abc123'] < (new Date() - 1000)) {
echo '<style data-inline-cacher="abc123" data-serve-from-cache="true"></style>';
}
else {
echo '<style data-inline-cacher="abc123" >' + $inlineStylesGoHere + '</style>';
} Note that the |
Had a further think about this today. Think of it as "inline by default". If the server detects a cookie which suggests it is cached already, then switch to the external approach ( Ideally we should have some service worker which intercepts any external requests to that This approach:
So biggest challenge atm is a) how to create that web worker to do all that in a timely fashion and b) how to initialise all that (probably have to inline the inline-cacher script in the HEAD) |
We need a way for the server to tell what has been cached on the client, and not just whether something is cached.
Currently, if you update the CSS for your site, there's no easy way to make sure your visitors' InlineCacher localStorage is cleared. We need to know when to call
InlineCacher.reset()
and send the latest inline styles.There are a few approaches we could take:
inline-cacher="1559076458"
)and invalidating if too old.inline-cacher="abc123def456"
) and invalidating if different to what's on the server.<style data-version="v1.2.3>
) and setting the cookie value to this (e.g.inline-cacher="v1.2.3"
), invalidating if too old.I'm keen to get this right from the beginning to avoid setting up any technical debt.
The text was updated successfully, but these errors were encountered: