Redirecting to the latest version of static resources

Hyungsuk Choi
2 min readNov 29, 2020

The best cache control for static resources is to rename files when their contents change. Adding a version or hash to the file name, such as https://v.011st.com/pc.common.1.0.20.js or https://v.011st.com/pc.common.e910auf39efb92fefzee.js.

And set the cache-control of HTML to no-cache and the cache control of static resources to max-age=31536000. Then, whenever the content of a static resource is changed, just change the version or hash value in HTML.

However, if there are many JSP using the script, updating the version on JSP is troublesome. In our case, whenever the GNB changes, we need to modify the script’s URL in many JSP scripts for all services. To solve this problem, we built the system that returns the latest version of the resource at the web server, not WAS, when a resource is requested.

The GNB header of 11st service

The network flow of the system is shown in the figure below as four steps.

  1. The client sends a request to the url, /11-gnb/dist/main.js, referenced in the html. This url has no version info.
  2. The server responds 302 by redirecting the request to the latest version of the resource, /11st-gnb@0.11.1/dist/main.js. The cache control for this response is no-cache.
  3. Then, the client sends the redirected request to the latest version of the resource.
  4. The server responds the resource, /11st-gnb@0.11.1/dist/main.js. The cache control for this response is max-age=31536000.

Each time the page is loaded, step (1) and (2) are executed,

If the version that was respond in step (2) has been fetched in one year, step (3) and (4) are skipped and the cached resource is used. If not, it goes through step (3) and (4), and the response is cached for one year.

For redirecting, we used Apache Module, mod_rewrite, and use a plain text mapping file, latest.txt. The module rewrite request URLs with rule-based rewriting engine.

We added L4 load balancing and CDN to this system. The cache-control of CDN follows the thing of the origin server. The composition is as follows.

--

--

Hyungsuk Choi

Hello. I am a programmer and familiar with Web FE and Node.js.