Thanks for the replies, everyone.

On Mon, Jun 19, 2017 at 8:42 PM, Bartosz Dziewoński <[email protected]> wrote:
> I don't think "unloading" modules will ever be a thing. While
> ResourceLoader could be made to keep track of modules' CSS to be able to
> remove it, we can't "unload" JavaScript modules at all (because their code
> has already executed), so I'm not sure if we'd want to add such special
> case.
I still think it'd make sense to have some sort of official support
for unloading modules' CSS, whether we're talking about CSS-only
modules or modules which happen to also include CSS. CSS and JS
obviously have different functions, and just like how you use
$out->addModules( 'some-module-name' ); to load JS modules and
$out->addModuleStyles( 'some-module-name' ); to load CSS modules in
PHP, why couldn't there be official support for unloading CSS modules?
Or failing that, support for a way to tell ResourceLoader, "yes, I
*really* want to reload this module again even if you think that it's
already loaded and thus there's no need to make another HTTP request".

> If you want a slightly less horrible hack than you do now – you could
> generate an appropriate load.php URL yourself (with &only=styles) and add
> that in a <link> tag to the page, much like we did back in the old days
> with importStylesheetURI(). ResourceLoader won't even know the module is
> loaded. And this way, you can remove the <link> tag later without messing
> with ResourceLoader's internals.
Thanks for the suggestion. While I didn't implement this at this time
-- simply because I managed to get my hacks working before you posted
this message -- I'm sure this is the route I'll have to take in the
future. For the time being, I solved the problem by using a cache
variable and caching loaded CSS there and instead of trying to
(unsuccessfully) call mw.loader.load() twice (or thrice etc.) I first
check cache and try to use the cached CSS if possible [1].

As always, code review of both the JS and PHP parts of the patchset
[2] is welcome, although the most acute problem (with the JS) is now
fixed and legoktm gave me a few good pointers on how to make the PHP
part saner. :-)

[1] https://gerrit.wikimedia.org/r/#/c/359643/6..7/ext.theme.livepreview.js
[2] https://gerrit.wikimedia.org/r/359643


Thanks and regards,
--
Jack Phoenix
MediaWiki developer

_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to