MrOtherGuy / fx-autoconfig

Load custom javascript in browser context
Mozilla Public License 2.0
164 stars 10 forks source link

About boot.jsm > loadScript #10

Closed Mitezuss closed 11 months ago

Mitezuss commented 2 years ago

Hi, i have a question about this line:

https://github.com/MrOtherGuy/fx-autoconfig/blob/76ca3d36276c0a13b306553c82d0d55f5c2b1fb3/profile/chrome/utils/boot.jsm#L241

On xiaoxiaoflood version, he had added the lastModifiedTime (to avoid the cache "problem"), extracted code:

Services.scriptloader.loadSubScript(script.url + '?' + script.file.lastModifiedTime, win, 'UTF-8');

So, what you think about that ?

In the Xiaoxiaoflood version, the script only be reload if reboot firefox (don't need purge cache). However, if the scripts were modified, with the firefox started (atleast one window), the changes on the script will not applied to a new window. Then, another alternative is add "new Date().getTime()" to avoid cache, and start a new script

Regards

PD: sry my bad englis -.-

MrOtherGuy commented 2 years ago

If I understand that correctly the intention is to load a new version of the custom script from the disk for each window (or whatever other document your script targets) - so for example you open Firefox and it executes your custom script. Then you modify the script, and after that open a new window. Now Firefox executes the new version for that new window. Is that correct?

I'm not sure if that's actually a good thing to do. It does feel convenient, but it doesn't feel right to let two or more windows run different scripts that could at least in theory be incompatible.

I could make it an optional script header so that script can be marked as not to be cached.

MrOtherGuy commented 2 years ago

Another option would be a global pref to set whether scripts should be cached or not.

Mitezuss commented 2 years ago

Is that correct?

Yes and not. That is because my bad english. (i hope can explain better to next)

Yes: because the script is reload when you close and open a new firefox (killing firefox and relaunch, without have to clear the cache) Not: because the script is not reload (if is modified, having atleast a window of firefox) when open a new window. (teorically the script should be reloaded, but is not... i don't know why, if the lastModifiedTime has change... So, how i said: If add "new Date().getTime()" the script is reload when open a new window; that is so rare... but work)

I think is a good idea have not to "clear cache" when you wanna apply some modified (i saw, on forums, some people having problem with that (because they don't know about the cache)

I could make it an optional script header so that script can be marked as not to be cached.

That sounds interesting, anyway I prefer all script not cache (so, directly mod the jsm)

Keep with your great work =). Regards.

MrOtherGuy commented 2 years ago

Okay I see what you mean now. It definitely sounds better if all windows do at least run the same version, and yet new script versions are picked up when the whole browser is restarted regardless of how you restart it.

But if that is the case, then it sounds to me that all those script versions are being put into cache. Now, I don't know how the cache mechanism works internally so maybe this isn't an issue, but it doesn't feel right to populate the cache with new version on every startup.

Anyway, this is a good feature is theory, but I think it requires some more thought.

Having the user explicitly mark scripts as not-to-be-cached seems kinda safe, however it still suffers from the fact that if the script is cached once then it requires cache to be cleared once to change it's status to ignore cache. I suppose that's better than nothing though.

MrOtherGuy commented 2 years ago

Sorry, I had forgotten about this. Anyway, the latest version of boot.jsm supports @ignorecache header in scripts - see example in readme.

The behavior is not exactly the same than in xiaoxiaoflood version, but I think it's better to let scripts opt into not caching than to implicitly disable caching completely.

MrOtherGuy commented 11 months ago

This is basically done