Update The Mysterious 404 Issue

steffeydev 2025-01-16 21:02:38 +00:00
parent 8200f2890b
commit 0e6c160180

@ -1,6 +1,6 @@
Within one day after changing the docker image used in production, the ERPNext client started reporting 404 errors when trying to load certain critical JS bundles. This was because the files they were asking for didn't actually exist. After a lot of digging, I discovered that the files being requested were actually the bundles from the previous docker image. Within one day after changing the docker image used in production, the ERPNext client started reporting 404 errors when trying to load certain critical JS bundles. This was because the files they were asking for didn't actually exist. After a lot of digging, I discovered that the files being requested were actually the bundles from the previous docker image.
Every time a docker build is done, a new `assets` folder is created in `frappe-bench/sites/assets`. The common cache-busting strategy of appending a value to the end of the bundle was used (e.g. `bundle.IQTBPBLP.js`). An `assets.json` file is created in the `assets` folder that maps the normal name, e.g. `desk.bundle.css` to the full path to that file, `/assets/frappe/dist/css/desk.bundle.RYMMWJSN.css`. Inside `frappe-bench/sites/assets`, besides `assets.json` are mostly just symlinks to the actual files in the `frappe-bench/apps` folder. Every time a docker build is done, a new `frappe-bench/sites/assets` folder is created. The common cache-busting strategy of appending a value to the end of the bundle was used (e.g. `bundle.IQTBPBLP.js`). An `assets.json` file is created in the `assets` folder that maps the normal name, e.g. `desk.bundle.css` to the full path to that file, `/assets/frappe/dist/css/desk.bundle.RYMMWJSN.css`. Inside `frappe-bench/sites/assets`, besides `assets.json` are mostly just symlinks to the actual files in the `frappe-bench/apps` folder.
The `frappe-bench/sites` folder is mounted in docker as a volume, because `frappe-bench/sites` contains instance-specific information like the host name and the DB creds that need to be persisted. This is awkward, since the `frappe-bench/sites/assets` should not be persisted and should always come from the current docker build. If you do persist it, you create the opportunity for the `assets.json` file to "point" to files that don't exist, thus leading to the 404 errors. The `frappe-bench/sites` folder is mounted in docker as a volume, because `frappe-bench/sites` contains instance-specific information like the host name and the DB creds that need to be persisted. This is awkward, since the `frappe-bench/sites/assets` should not be persisted and should always come from the current docker build. If you do persist it, you create the opportunity for the `assets.json` file to "point" to files that don't exist, thus leading to the 404 errors.