Any way to further optimize how the CSS is included on a page?
-
Is there any reason why the CSS for the font(s) & variation(s) is simply included as CSS directly on each webpage?
It’s certainly helpful that there’s some caching in how that inline CSS is being pulled into a page, but I’m wondering why it wouldn’t be better to have it where that CSS is then saved out as a CSS file to then be enqueued on pages accordingly (or at least available as a setting where it’s a dropdown to choose between “inline” [current method] or “saved to filesystem” [newly suggested method] for how the CSS is loaded onto pages; other plugins [ex. Max Mega Menu, assorted page builders, etc.] have done something similar when custom CSS is involved to allow for a potentially more optimal way of loading their custom CSS for visitors.)
I bring this up since I’m seeing something like 45KB of inline CSS on a site that’s then being included in the HTML of every single webpage when using this plugin with 3 fonts selected. I imagine a site with a good handful of fonts would see its webpage filesizes increase even further & potentially to a rather noticeable degree.
– Potential Implementation –
Couldn’t it be set up so this plugin has a folder in wp-content/uploads/ which then has the CSS that’d otherwise be included directly onto all webpages be saved out as a CSS file & enqueued on pages to keep the webpage itself slimmer while also taking advantage of browser caching, making that CSS more available to minify/combine via optimization plugins, etc.?
At that point, I’d imagine the CSS files could be named with timestamps so a webpage that’s cached server-side & might want to pull an older version of the CSS can do so while freshly generated pages can have it grab the latest timestamp on record for that CSS (while then having it clean up those older CSS files after a set [possibly configurable] duration like a month or so…? *Possibly then doing so whenever the plugin’s settings are saved to avoid needing to get cron events involved while that’s when it would generate the new CSS file anyway to then also check the existing CSS file timestamps to delete anything that’s older than the max age.) I also bring up timestamped files since this would need to account for browser caching where having it keep the same file name might cause changes to the plugin’s settings to be quite delayed for visitors depending on a site’s browser caching setup.
Not saying it needs to be the new default (though that could certainly be considered.) I just think there can be a case where offering this would help optimize the performance of a site in a few, potentially impactful, ways (especially when the number of fonts adds up for a given site; load it once & have it be in browser cache while browsing additional pages compared to having all of that CSS be loaded as part of every webpage visited seems like a clear optimization opportunity for this plugin.) Maybe this is already an option that I haven’t come across so definitely let me know if there’s a way to do this. Otherwise, I’d be curious to hear what the thoughts/concerns are about getting this added as an option.
- The topic ‘Any way to further optimize how the CSS is included on a page?’ is closed to new replies.