Hi all,
It seems the Common.css on my website is pretty small but Resource Loader loads it using a <link> tag in the head. I have read that it will be better to instead inline the styles or even load them later.
What is the right way to go about this? Any suggestions are welcome.
Also see https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery
Regards, Nischay Nahata
There is one important reason why we use <link> instead of <style>…</style>: when the rendered page HTML is cached, e.g. using a caching proxy like Varnish [1] or MediaWiki file cache [2], then if we used <style>…</style>, you would have to purge every page on the wiki before changes to MediaWiki:Common.css would actually take effect, because the CSS would be embedded in the cached HTML.
Using <link> means that it only takes as long as it takes the cached resource to expire in the users' browsers. (By default, they are set to expire after 5 minutes.)
If you don't have caching enabled, then of course that wouldn't matter – but also, if you don't have caching enabled, then that is probably a much worse performance problem than not embedding the styles :)
[1] https://www.mediawiki.org/wiki/Manual:Varnish_caching [2] https://www.mediawiki.org/wiki/Manual:File_cache
Thanks for the reply.
I do use the file cache and yes, there could be performance issues with purging too many problems at once. But again there's a situation where I can avoid using Common.css altogether so I think there should be a way to turn the module off. I don't know what happens if the common.css is empty, I will try that out.
Regards, Nischay Nahata
On Fri, Jul 20, 2018 at 12:04 AM Bartosz Dziewoński matma.rex@gmail.com wrote:
There is one important reason why we use <link> instead of
<style>…</style>: when the rendered page HTML is cached, e.g. using a
caching proxy like Varnish [1] or MediaWiki file cache [2], then if we used <style>…</style>, you would have to purge every page on the wiki before changes to MediaWiki:Common.css would actually take effect, because the CSS would be embedded in the cached HTML.
Using <link> means that it only takes as long as it takes the cached resource to expire in the users' browsers. (By default, they are set to expire after 5 minutes.)
If you don't have caching enabled, then of course that wouldn't matter – but also, if you don't have caching enabled, then that is probably a much worse performance problem than not embedding the styles :)
[1] https://www.mediawiki.org/wiki/Manual:Varnish_caching [2] https://www.mediawiki.org/wiki/Manual:File_cache
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
It loads the link even though the content is blank :/
Regards, Nischay Nahata
On Fri, Jul 20, 2018 at 11:25 AM Nischay Nahata nischayn22@gmail.com wrote:
Thanks for the reply.
I do use the file cache and yes, there could be performance issues with purging too many problems at once. But again there's a situation where I can avoid using Common.css altogether so I think there should be a way to turn the module off. I don't know what happens if the common.css is empty, I will try that out.
Regards, Nischay Nahata
On Fri, Jul 20, 2018 at 12:04 AM Bartosz Dziewoński matma.rex@gmail.com wrote:
There is one important reason why we use <link> instead of
<style>…</style>: when the rendered page HTML is cached, e.g. using a
caching proxy like Varnish [1] or MediaWiki file cache [2], then if we used <style>…</style>, you would have to purge every page on the wiki before changes to MediaWiki:Common.css would actually take effect, because the CSS would be embedded in the cached HTML.
Using <link> means that it only takes as long as it takes the cached resource to expire in the users' browsers. (By default, they are set to expire after 5 minutes.)
If you don't have caching enabled, then of course that wouldn't matter – but also, if you don't have caching enabled, then that is probably a much worse performance problem than not embedding the styles :)
[1] https://www.mediawiki.org/wiki/Manual:Varnish_caching [2] https://www.mediawiki.org/wiki/Manual:File_cache
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
The <link> will not be generated if the page is actually deleted, rather than existing but empty.
I tried that, its still showing up.
Regards, Nischay Nahata
On Fri, Jul 20, 2018 at 4:28 PM Bartosz Dziewoński matma.rex@gmail.com wrote:
The <link> will not be generated if the page is actually deleted, rather than existing but empty.
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
I tested locally and deleting MediaWiki:Common.css removed the <link> for 'site.styles' module from pages.
Make sure that you're not actually viewing cached page HTML that still has it.
Also make sure that you're not using the other MediaWiki pages that are included in this module: MediaWiki:Print.css and MediaWiki:Vector.css (or MediaWiki:Monobook.css, etc., depending on the skin).
If you still see this behavior and want to try debugging it, start in ResourceLoaderWikiModule::isKnownEmpty() and its callers, this is the method that decides whether the <link> will be generated.
Also, I should note that I tested with MW 1.32 alpha (Git master). I don't know if older versions behave differently.
Okay, that's good to know. I am still on 1.26 so it may have changed at a later stage.
Thank you
On Fri, Jul 20, 2018, 9:20 PM Bartosz Dziewoński matma.rex@gmail.com wrote:
Also, I should note that I tested with MW 1.32 alpha (Git master). I don't know if older versions behave differently.
-- Bartosz Dziewoński
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org