WebOptimizer
                                
                                
                                
                                    WebOptimizer copied to clipboard
                            
                            
                            
                        Is using S3 (or other stable file store) required to prevent files missing when HTML cached?
We currently use Squishit (https://github.com/jetheredge/SquishIt), but are looking at WebOptimizer as part of our .Net5 transition.
I have trouble understanding how, without a backing filestore, WebOptimizer handles working with cached HTML.
For example - let's say we have a page, who's HTML is cached at the server. Within that file, there is a link:
<link rel="stylesheet" href="/css/bundle.css?v=khQM-MH-kfQzXMTi6dihWqDfoGk">
I understand this key relates to a bundle, which WebOptimiser will serve back to the user.
However, let's say we release a new version of our code. As the cached HTML survives across deploys, a user could, after deploy request the same file again (/css/bundle.css?v=khQM-MH-kfQzXMTi6dihWqDfoGk). In this case the files that used to make up this key will no longer exist, and so presumably the CSS/JS will fail to load.
I can see there is a UseFileProvider, which I'm hoping can be backed by Amazon S3 - is there an example implementation of this? And is the logic above correct that to survive across deploys, a custom file provider is required?
.NET Core automatically computes hashes for static files. It is built-in functionality. Look at the IFileVersionProvider and "asp-append-version Feature"
.NET Core automatically computes hashes for static files. It is built-in functionality. Look at the IFileVersionProvider and "asp-append-version Feature"
I'm not sure this helps? This is telling the browser to fetch updated versions of a static JS file, when getting fresh HTML from the server. This is quite a different problem.
If a site / client was to cache the HTML response across deploys, then the point is that we'd be pointing to an old file still. Without a backing file store, that survives across deploys, how does this work? The file no longer exists...
IFileVersionProvider isn't just for the browser. You can use the resulting hash to determine that the file has changed since the last deploy. Thus, if the cached file is not found or the hash of the origin file has changed, then the cache must be recreated.
OK, so we return some HTML to the client:
<link rel="stylesheet" href="/css/bundle.css?v=khQM-MH-kfQzXMTi6dihWqDfoGk">
The client saves the whole HTML page locally on their machine.
We then deploy a new version of code, which modifies the bundle (and all newly returned HTML returns a new version/hash for new requests).
The original client loads the saved HTML, and this makes a request for /css/bundle.css?v=khQM-MH-kfQzXMTi6dihWqDfoGk - what happens? Presumably the server has no concept of this version/hash?