You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/reference.adoc
+19-3
Original file line number
Diff line number
Diff line change
@@ -159,22 +159,38 @@ We often talk about the http://en.wikipedia.org/wiki/Web_cache#Cache_control[cac
159
159
The `max-age` value defines how long the static should be kept before checking for new update.
160
160
The same problem on the server appears: you don't know how long the user will load an old version from browser cache until its expiry.
161
161
Consequently, you may probably set a short value.
162
-
When the statics expires, the browser sends an HTTP request to the server to know if the data is fresh or not.
162
+
When the statics expires, the browser sends a HTTP request to the server to know if the data is fresh or not.
163
163
If data is fresh, server responds with a status code `304 - not modified` and an empty body.
164
164
However, it sends the fresh data in the body.
165
165
What is unfortunate here is that the browser could poll the server synchronously and, at the end, see that nothing changed.
166
166
WUIC does not use the cache control for that reason.
167
167
168
168
The HTTP response should instead contains a "expires" directive which tells the browser to keep the statics for a very long time.
169
169
Since cache entry is associated the path URL of the static, WUIC has just to modify this path to evict the cache.
170
-
How it does the trick? By adding in the URL a `CRC32` hash based on all nuts name processed by the workflow and their last modification timestamp.
170
+
How it does the trick? By adding in the URL a version number identifying all nuts state processed by the workflow.
171
171
When nuts are changed, it could be detected on redeployment or during a polling operation.
172
-
Both cases will result in the computation of a different `CRC32` hash which will change the static URL, which does not corresponds to any cache entry on the browser.
172
+
Both cases will result in a different version number which will change the static URL, which does not corresponds to any cache entry on the browser.
173
173
This is the way WUIC prevent any unnecessary HTTP request on the server while maintaining fresh statics loaded by the browser.
174
174
175
175
TIP: with HTTP/2 `server-push` is always initiated and stopped as soon as the browser has detected that the resource is actually cached.
176
176
With `resource-hint`, the browser will check first that resource is not cached before creating a new HTTP request.
177
177
178
+
==== Version strategy
179
+
180
+
Three strategies exist for computing the version number:
181
+
182
+
* `Last modification timestamp`: by default WUIC uses the last modification date associated to the resource on the disk.
183
+
It's fast, but if your build process touch the file, it will lead to a different version number while the content has not changed.
184
+
* `CRC32 content hash`: by setting the value `true` to the `c.g.wuic.dao.contentBasedVersionNumber` property, WUIC will read the entire content
185
+
to obtain a `CRC32` checksum. It's slower but you have the guarantee to keep intact the browser cache if you don't update the file
186
+
between two releases.
187
+
* `Fixed version number`: if you set a value for the `c.g.wuic.fixedVersionNumber` property, WUIC will always use this value as version number.
188
+
You can for instance use a version of your release.
189
+
This strategy will lead to a browser cache refresh each time you release a new version.
190
+
It requires to change the version yourself but this strategy allows to modified URL that can't be resolved.
191
+
For instance, if WUIC can't resolve a background url in a `CSS` file, it does not process the referenced image.
192
+
However it can at least add the fixed version number as a parameter to the URL (for instance `?versionNumber=20150808`).
193
+
178
194
== Best effort
179
195
180
196
By default at runtime, any cache `Engine` executes the entire workflow when the desired resources are not in the cache.
0 commit comments