Page MenuHomePhabricator

Including the same TemplateStyles stylesheet multiple times increases unstrip post-expand size
Open, Needs TriagePublic

Description

This is related to T200206 but not the same.

Although TemplateStyles stylesheets are deduplicated at the end, they still count toward the unstrip post-expand size of the page. If a template using that stylesheet is transcluded many times on a page, it could exceed the unstrip post-expand size limit.

A fix not possible on WMF wikis is to create a deduplication template using the Variables extension. Replace the templatestyles tag with {{Deduplicate | name=Item | 1=<templatestyles src="Item/styles.css"/> }}. The content of the deduplication template would be {{#varexists: {{{name|}}} | | {{{1|}}} {{#vardefine:{{{name|}}}|T}} }}, which will ensure that the tag is only included once on the page. This is used on Blue Archive Wiki.

Another workaround is to put the content of the stylesheet in Common.css or a gadget loaded conditionally only for pages in a tracking category inserted by the template.

Event Timeline

@stjn I believe it was you who suggested reporting this on Phabricator on Discord since the username matches your profile.

Yes, thanks. This does seem like a flaw, since any extensive use of one template, no matter how small it is, would eventually break the page once a certain number of elements get present. Although it didn’t yet appear in the WMF wikis, there might be a point where it ends up happening, as more and more templates get converted to TS model.

This is related to T200206 but not the same.

How is it not same? Increase in unstrip post-expand size is because of those <link> tags.

This comment was removed by stjn.

Sorry for misinforming in earlier comment. It is not exactly related because the unstrip post-expand size (UPES) increase happens in the size of the original stylesheet, not in the size of a <link> tag generated by deduplication. So if someone adds some more CSS to the styles page (let’s say 100 bytes), every instance ends up contributing 100 bytes to UPES, 400 for 4 template calls, 800 for 8 template calls, etc.

Okay, I see it now.

I don't think this is (easily) fixable though. The unstrip post-expand output does include the full CSS multiple times. They are deduplicated later in an OutputTransformStage.