Implement userscripts cache
This idea was initially formed in #424, and we cannot read files in "save location" synchronously (if they were not downloaded) due to the asynchronous nature of the "File Provider".
So a good solution is that we cache them in an internal synchronously readable location and synchronize and update asynchronously.
Now let us think further and document this issue.
We should cache the parsed structured data
Compared to the current reading and parsing content from a userscript file every time. We should cache the parsed metadata object and the separate userscript code. It can definitely help us reduce calculations, delays, and energy consumption:
- https://github.com/quoid/userscripts/issues/557
- https://github.com/quoid/userscripts/issues/637
Update the cache only if the original file changes are detected.
Going further, we could even minify the userscript code to improve the efficiency of transmission and parsing. Note that we should provide an option to disable minify or ship sourcemap for user debugging.
The options worth investing in might be:
- https://www.npmjs.com/package/oxc-minify
-
oxcis used as buildrolldownand will replacerollupandesbuildin the future invite.
We should also refactor @require to make it pre-bundled and stored in the cache instead of the current way.
Cache location and bundle method
Possible cache locations are the native app container or browser.storage.
We could use the bundler native version in swfit or wasm version in browser.
Currently the main part of the issue has been verified and implemented:
-
We can now read files from the "File Provider" asynchronously (no need to "Keep Downloaded")
- Even if the files is evicted, as long as they has not been modified, we will not download them and keep the injection process work
- But if you try to open them in the editor, they will always be downloaded and edited or saved from/to the source
-
Perform various write operations only after scripts file modification
- Avoid repeatedly reading and parsing script contents, significantly reducing energy consumption
- No more frequent updates and writes to mainifest files, significantly reducing unnecessary disk writes.
-
This will serve as the basis for implementing and improving many other features, as it implements new UUID tracking and synchronization mechanisms