Wp-rocket: Rewrite URLs on @import rule

Created on 3 Nov 2020  路  7Comments  路  Source: wp-media/wp-rocket

Is your feature request related to a problem? Please describe.
When the CDN feature is enabled, we rewrite URLs of static assets that are in the source code of the page and URLs in CSS files but if a URL to a CSS is requested using an @import rule the URL is not rewritten, this means that these CSS are not served from the CDN and GTMetrix listed those files on the Use a Content Delivery Network (CDN) advice:

https://jmp.sh/TbiGoXP
https://i.imgur.com/H399oFA.png
https://i.imgur.com/i3lBFTt.png

Describe the solution you'd like
Rewrite the URLs on the @import rule for all static assets to be loaded from the CDN

Related ticket: https://secure.helpscout.net/conversation/1325289421/207627?folderId=2952229

CDN low enhancement wontfix

Most helpful comment

Processing @import-ed files like any other will solve other problems and reduce some tickets since these files don't get any optimizations applied on them currently so it creates tickets related to preload key requests, minification, cdn rewrites etc.

All 7 comments

Since @import counts as a request and will be render-blocking since it sits on the top of the file, wouldn't it be better if we just executed the @import and added the actual content to the combined files?
This will avoid the additional request and any delay in parsing the CSS file.

Since @import counts as a request and will be render-blocking since it sits on the top of the file, wouldn't it be better if we just executed the @import and added the actual content to the combined files?

@DahmaniAdame This makes sense. Not something we do for anything else right now, but should be doable. Pinging @Tabrisrp / @GeekPress For your input. If this makes sense in theory, I can do some benchmarking to see if it adds value.

Processing @import-ed files like any other will solve other problems and reduce some tickets since these files don't get any optimizations applied on them currently so it creates tickets related to preload key requests, minification, cdn rewrites etc.

@arunbasillal To discuss/track the general @import issue, i.e. that we don't process those files at all, should I start a new issue? Or, maybe we can just change the title on this one?

@GeekPress I believe you are currently working on bench-marking @import right? Maybe that enhancement can be merged with this discussion?

Yes, I'm working on this problem to check if it's a common problem whatever the @import is from an internal or external file. The best solution here will be to merge the imported files into the original file.

@webtrainingwheels We will close this issue once the new one about merging the import file will be created. I will do that.

Closed in favor of #3539 which will solve this problem in the same time.

Was this page helpful?
0 / 5 - 0 ratings