Skip to content

luci-base: package update based cache-busting string#7725

Merged
systemcrash merged 1 commit into
openwrt:masterfrom
remittor-pr:fix-header-ut
Apr 14, 2025
Merged

luci-base: package update based cache-busting string#7725
systemcrash merged 1 commit into
openwrt:masterfrom
remittor-pr:fix-header-ut

Conversation

@remittor

@remittor remittor commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

Problem:

After updating the js-part of any package, the user is forced to clear the browser cache.

Fix:

Each time a package is removed or installed, the contents of the /lib/apk/db/installed file are changed.
This fix add the modification time of the /lib/apk/db/installed file to the version of the main LuCI package (for each js-file).

Additional info and screenshots: https://forum.openwrt.org/t/214025/3

  • This PR is not from my main or master branch 💩, but a separate branch ✅
  • Each commit has a valid ✒️ Signed-off-by: <my@email.address> row (via git commit --signoff)
  • Each commit and PR title has a valid 📝 <package name>: luci-base first line subject for packages
  • Incremented 🆙 any PKG_VERSION in the Makefile
  • Tested on: (filogic, openwrt 24.10.0, Chrome 135) ✅
  • ( Preferred ) Mention: @remittor the original code author for feedback
  • ( Preferred ) Screenshot or mp4 of changes:

image

@remittor

Copy link
Copy Markdown
Contributor Author

Related commits:

  1. d7d9772
  2. e0650da

@jow-

jow- commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

Please try this approach instead:

diff --git a/modules/luci-base/ucode/runtime.uc b/modules/luci-base/ucode/runtime.uc
index f14bf74480..81afac9f60 100644
--- a/modules/luci-base/ucode/runtime.uc
+++ b/modules/luci-base/ucode/runtime.uc
@@ -1,7 +1,7 @@
 // Copyright 2022 Jo-Philipp Wich <jo@mein.io>
 // Licensed to the public under the Apache License 2.0.
 
-import { access, basename } from 'fs';
+import { access, basename, stat } from 'fs';
 import { cursor } from 'uci';
 
 const template_directory = '/usr/share/ucode/luci/template';
@@ -179,6 +179,7 @@ export default function(env) {
        self.env.media = media;
        self.env.theme = basename(media);
        self.env.resource = uci.get('luci', 'main', 'resourcebase');
+       self.env.resource_version = stat('/usr/lib/opkg/status')?.mtime ?? stat('/lib/apk/db/installed')?.mtime ?? 0;
        self.env.include = (...args) => self.render_any(...args);
 
        return self;
diff --git a/modules/luci-base/ucode/template/header.ut b/modules/luci-base/ucode/template/header.ut
index 7a8462d61d..e15069333d 100644
--- a/modules/luci-base/ucode/template/header.ut
+++ b/modules/luci-base/ucode/template/header.ut
@@ -7,7 +7,7 @@
        include(`themes/${theme}/header`);
 -%}
 
-<script src="{{ resource }}/luci.js"></script>
+<script src="{{ resource }}/luci.js?v={# PKG_VERSION #}-{{ resource_version }}"></script>
 <script>
        L = new LuCI({{ replace(`${ {
                media          : media,

@jow-

jow- commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

The {# PKG_VERSION #} placeholder is substituted at build time with the git based revision, the {{ resource_version }} placeholder is substituted at runtime with the stat().mtime result.

@systemcrash

Copy link
Copy Markdown
Contributor

The {# PKG_VERSION #} placeholder is substituted at build time with the git based revision, the {{ resource_version }} placeholder is substituted at runtime with the stat().mtime result.

I like this (@jow-'s) approach - this was abstractly what I had in mind when I commented in the forums.

@systemcrash

Copy link
Copy Markdown
Contributor

I would swap the two paths around since SNAPSHOT is all apk from here on in:

+       self.env.resource_version = stat('/lib/apk/db/installed')?.mtime ?? stat('/usr/lib/opkg/status')?.mtime ?? 0;

@systemcrash systemcrash changed the title luci-base: Added patching of version into header.ut luci-base: package update based cache-busting string Apr 14, 2025
@remittor

Copy link
Copy Markdown
Contributor Author

Please try this approach instead:

image

I would swap the two paths around since SNAPSHOT is all apk from here on in:

image

Result:

image

Worked!

@systemcrash

systemcrash commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

Perhaps name resource_version something which reflects what it is - like... pkgs_update_time?

@remittor

Copy link
Copy Markdown
Contributor Author

Perhaps name resource_version something which reflects what it is - like... pkgs_update_time?

let @jow- make a new commit. So that everything is perfect.

@systemcrash

Copy link
Copy Markdown
Contributor

You're already here doing it @remittor - just update your commits :)

@systemcrash

Copy link
Copy Markdown
Contributor

You weren't asked to.

Problem:
After updating the JS-part of any package, the user is forced to clear
the browser cache.

Fix:
Each time a package is removed or installed, the contents of the
"/lib/apk/db/installed" file are changed.
This fix add the modification time of the "/lib/apk/db/installed" file
to the version of the main LuCI package (for each js-file).

Signed-off-by: Oleg S <remittor@gmail.com>
@systemcrash
systemcrash merged commit f6f82b5 into openwrt:master Apr 14, 2025
@systemcrash

Copy link
Copy Markdown
Contributor

Merged. Thanks @remittor

remittor added a commit to remittor/zapret-openwrt that referenced this pull request Apr 28, 2025
remittor added a commit to remittor/zapret-openwrt that referenced this pull request May 5, 2025
@remittor

remittor commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

OpenWrt 25.12-rc1
image
For some reason, the suffix isn't forming. There's not even a dash.

In 25.12-rc2 - same

But when viewing the source code of the page, the time is visible:
image

@remittor

Copy link
Copy Markdown
Contributor Author

On OpenWrt 24.10 this patch works as intended:
image

@remittor

remittor commented Jan 20, 2026

Copy link
Copy Markdown
Contributor Author

The cause has been identified: this is a custom Argon theme ;-)

Same problem:
jerrykuku/luci-theme-argon#604 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants