Skip to content

Commit

Permalink
perf: Improve caching of root js files (wireapp#17618)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Jun 19, 2024
1 parent 4dba7b2 commit b6568e1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 6 additions & 2 deletions server/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ class Server {
this.app.use(nocache());
} else {
this.app.use((req, res, next) => {
// If the user agent adds a v param, it means that its requesting a particular version of the file and that could be cached forever since the file will never change.
const hasCacheVersionParam = req.query.v && typeof req.query.v === 'string';
const oneYear = 31536000;
const maxAge = hasCacheVersionParam ? oneYear : this.config.CACHE_DURATION_SECONDS;
const milliSeconds = 1000;
res.header('Cache-Control', `public, max-age=${this.config.CACHE_DURATION_SECONDS}`);
res.header('Expires', new Date(Date.now() + this.config.CACHE_DURATION_SECONDS * milliSeconds).toUTCString());
res.header('Cache-Control', `public, max-age=${maxAge}`);
res.header('Expires', new Date(Date.now() + maxAge * milliSeconds).toUTCString());
next();
});
}
Expand Down
14 changes: 7 additions & 7 deletions src/page/auth.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

<title><%= BRAND_NAME %></title>

<script src="../min/basicBrowserFeatureCheck.js?<%= VERSION %>"></script>
<script src="../min/checkBrowser.js?<%= VERSION %>"></script>
<script src="../min/basicBrowserFeatureCheck.js?v=<%= VERSION %>"></script>
<script src="../min/checkBrowser.js?v=<%= VERSION %>"></script>
</head>

<body>
<div id="main"></div>
<script src="../config.js?<%= VERSION %>"></script>
<script src="../min/dexie.js?<%= VERSION %>"></script>
<script src="../min/vendor.js?<%= VERSION %>"></script>
<script src="../min/runtime.js?<%= VERSION %>"></script>
<script src="../min/auth.js?<%= VERSION %>"></script>
<script src="../config.js?v=<%= VERSION %>"></script>
<script src="../min/dexie.js?v=<%= VERSION %>"></script>
<script src="../min/vendor.js?v=<%= VERSION %>"></script>
<script src="../min/runtime.js?v=<%= VERSION %>"></script>
<script src="../min/auth.js?v=<%= VERSION %>"></script>
</body>
</html>
16 changes: 8 additions & 8 deletions src/page/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<title><%= BRAND_NAME %></title>

<script src="./min/basicBrowserFeatureCheck.js?<%= VERSION %>"></script>
<script src="./min/checkBrowser.js?<%= VERSION %>"></script>
<script src="./min/basicBrowserFeatureCheck.js?v=<%= VERSION %>"></script>
<script src="./min/checkBrowser.js?v=<%= VERSION %>"></script>
</head>

<body>
Expand Down Expand Up @@ -88,11 +88,11 @@
</div>
</main>

<script src="./min/loader.js?<%= VERSION %>"></script>
<script src="./config.js?<%= VERSION %>"></script>
<script src="./min/dexie.js?<%= VERSION %>"></script>
<script src="./min/vendor.js?<%= VERSION %>"></script>
<script src="./min/runtime.js?<%= VERSION %>"></script>
<script src="./min/app.js?<%= VERSION %>"></script>
<script src="./min/loader.js?v=<%= VERSION %>"></script>
<script src="./config.js?v=<%= VERSION %>"></script>
<script src="./min/dexie.js?v=<%= VERSION %>"></script>
<script src="./min/vendor.js?v=<%= VERSION %>"></script>
<script src="./min/runtime.js?v=<%= VERSION %>"></script>
<script src="./min/app.js?v=<%= VERSION %>"></script>
</body>
</html>

0 comments on commit b6568e1

Please sign in to comment.