core icon indicating copy to clipboard operation
core copied to clipboard

backend static assets should explicitly leverage browser cache

Open yolabingo opened this issue 6 months ago • 0 comments

Problem Statement

Maybe this is a spike.

Where possible:

  1. dotCMS backend static file assets should use versioned, cache-able, URLs
  2. responses for these files should set a long browser cache time with the header cache=control: max-age=<seconds>

Based on the sheer number of files, this is primarily a concern with .js files vs .css files.

Observed patterns: No static file responses from the backend set a cache TTL for browser cache.

Some files appear to be hashed

https://<cloudcustomer>-staging-1.dotcms.cloud/dotAdmin/chunk-YOYI67ER.js
https://<cloudcustomer>-staging-1.dotcms.cloud/dotcms-webcomponents/p-2898e71d.entry.js

Use of versioned query strings is inconsistent

https://<cloudcustomer>-staging-1.dotcms.cloud/dwr/interface/BrowserAjax.js?b=24.04.24_lts_v7
https://<cloudcustomer>-staging-1.dotcms.cloud/dwr/interface/CategoryAjax.js
https://<cloudcustomer>-staging-1.dotcms.cloud/dwr/interface/ContainerAjax.js?b=24.04.24_lts_v7
https://<cloudcustomer>-staging-1.dotcms.cloud/dwr/interface/ContentletAjax.js
https://<cloudcustomer>-staging-1.dotcms.cloud/html/js/dojo/custom-build/dojo/dnd/move.js
https://<cloudcustomer>-staging-1.dotcms.cloud/html/js/dojo/custom-build/dojo/dojo.js?b=24.04.24_lts_v7
https://<cloudcustomer>-staging-1.dotcms.cloud/html/js/dojo/custom-build/dojo/fx/Toggler.js

Some files are served from / it might be wise to move these to a subdirectory. https://demo.dotcms.com/dotAdmin/chunk-W6WLCTMX.js

Issues:

  1. Cloud customers sometimes report buggy backend behavior after an upgrade, the fix for which is to clear the browser cache. We suspect this is because some js files using unversioned URL changed in the upgrade.
  2. Performance

It is the case that browsers will cache most js files for a time if they do not set a cache ttl in the response. We don't know how long these are cached, nor do we have any control over that behavior. Due to browser limits on the number of concurrent connections to a single host, load times for a page that requests a large number of blocking file assets from a single host can be slow even when the individual files load relatively quickly. https://stackoverflow.com/a/30064610/1289093

| Browser              | Connections per Domain [host]  |  
| -------------------- | ------------------------------ | 
| Chrome 81            | 6 [^note1]                     | 
| Edge 18              | *same as Internet Explorer 11* | 
| Firefox 68           | 9 [^note1] or 6 [^note3]       | 
| Internet Explorer 11 | 12 [^note4]                    | 
| Safari 13            | 6 [^note1]                     |

Longer term, we could move toward serving some these files from a shared dotCDN bucket for cloud customers. Aggressive and thorough browser caching directly from the backend would obviate most of the CDN benefits.

Steps to Reproduce

grab a HAR file after clicking around the backend

Acceptance Criteria

Ongoing improvement of browser cache use in the backend

dotCMS Version

all

Proposed Objective

Application Performance

Proposed Priority

Priority 3 - Average

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

backend-static-files.txt

Assumptions & Initiation Needs

First do no harm

yolabingo avatar Aug 26 '24 15:08 yolabingo