JavaScript modules and browser cache

Marian C.
10 min readAug 7, 2021

Can modules be used in production not bundled?

Browser cache

When a browser request a file from some URL for the first time, it might save the entire HTTP response, both headers and body, into the cache. Next time the browser needs the same file, it potentially has several options:

  • to reload the file from the server
  • to reuse the cached file
  • before reusing the cached file, to request from the server to resend the file but only if it differs from the cached one
  • to reuse the cached file and then to request from the server to resend the file if it differs from the cached one

From a user’s perspective, those options differ in the time needed for their completion. Loading data from a local disk is faster that loading it from a network. Receiving a file is slower than receiving an empty response.

Whether a browser caches a server response and what it later does with the cached response depends on the value of Cache-Control header of the response. Basically, the browser uses its cache according to the directives of a server that follows the instructions of a web application.

Why use the browser cache?

--

--

Marian C.
Marian C.

Written by Marian C.

Java, JavaScript and SQL developer. Interested in data collection and visualization.

Responses (1)