How to ensure that the wasm file accessed by users is always the latest after project modifications?
-
I am currently using the wasm kit to compile a Qt project, and then I get some static web files, such as xxx.wasm and xxx.js. I deploy these files to my backend server, and everything works fine.
However, I am now encountering a problem: after modifying the Qt project and recompiling, the new files are not accessed by others in a timely manner due to browser caching. So I am thinking of modifying the dynamic loading logic of the wasm/js files. For example, the current link is https://web.jasonserver.com:10035/JQClock/JQClock.wasm. It can be modified to https://web.jasonserver.com:10035/JQClock/JQClock.wasm?t=123456, and after each compilation, the 123456 at the end can be changed to ensure that users access the latest version. This may require modifying the loading logic in the js file, but the js file is dynamically generated. I want to know how to modify it appropriately.
-
Because the caching rules of browsers are quite complex, I tried modifying Cache-Control on the backend server, but this doesn't necessarily work, and it might be a setting issue on my part? However, I haven't found the real cause.
Therefore, I think if it's possible to modify the loading logic of the wasm files, it might be the most suitable and reliable solution. For example, adding an MD5 hash or a random marker.
-
@JasonWong said in How to ensure that the wasm file accessed by users is always the latest after project modifications?:
For example, the Webpack tool modifies related files and adds an MD5 hash each time it packages. Can we have similar logic in Qt wasm kit?
That's what I did in my project... I generate a unique UID for the current build when building and save it to text file, this text file is later uploaded to the website. When the user enters the website, the website automatically fetches the latest UID in this text file (make sure you fetch it through POST so you don't get a cached version).
Then you compare the running UID with the one downloaded, if they match everything is ok, otherwise you ask the user to update the website (or update it automatically) by forcing a POST on the .wasm file (so the browser doesn't fetch the cached .wasm file) and then refresh the webpage; you will end up with the latest version.