[JS] Force update js-file in browser after upgrade luci-app-ANY

Problem

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

Proposed Solution

Add the version of the ipk-package to which the file belongs to the JS-file name.
Instead, all JS-files are now appended with a common version of LuCI.

All files in the package are known. The version is also known:

root@OpenWrt:# opkg files luci-app-zapret
Package luci-app-zapret (66-20241025) is installed on root and has the following files:
/www/luci-static/resources/view/zapret/service.js
/www/luci-static/resources/view/zapret/settings.js
/usr/share/rpcd/acl.d/luci-app-zapret.json
/www/luci-static/resources/view/zapret/tools.js
/usr/share/luci/menu.d/luci-app-zapret.json

root@OpenWrt:# opkg info luci-app-zapret
Package: luci-app-zapret
Version: 66-20241025
Depends: libc, zapret
Status: install user installed
Architecture: all
Installed-Time: 1729956777

I found a pretty similar problem on GitHub.
And they advised that the user should manually clear the cache in the browser.

@jow , can you comment on my problem that I described?

Each time a package is removed or installed, the contents of the /usr/lib/opkg/status file are changed.
That's why I decided to add the modification time of the /usr/lib/opkg/status file to the version of the main LuCI package (luci-base).

Here is the implementation of this method:

Here is the place that this method patches:

Result:

Now the browser is simply forced to request new js-files from the router.

Could work, but the patch breaks after 24.10 where package manager becomes apk.

On the snapshot, instead of file /usr/lib/opkg/status, there is file /lib/apk/db/installed.
Its contents also change after removing and installing packages.
Therefore, it is very easy to adapt my patch for apk.

Fixing this caching problem is a bit of chicken or egg problem. Going for the cache busting string is a good move, but perhaps something can be done on the luci JS side by simply checking for the last update time of either of those files in a promise, which when resolved, completes the string.

Is that something you've looked at?

Resolved by https://github.com/openwrt/luci/pull/7725

1 Like