Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts inside CSS file have a bad path generated #40

Open
Creativico opened this issue Sep 17, 2022 · 4 comments
Open

Fonts inside CSS file have a bad path generated #40

Creativico opened this issue Sep 17, 2022 · 4 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@Creativico
Copy link

Creativico commented Sep 17, 2022

Description:
So this problem occurs when I have a CSS file with following url for fonts:
@font-face{ .... font-family:eicons;src:url('https://mycdnapi/m:0/a:https://www.mysite.com/wp-content/plugins/elementor/assets/lib/eicons/fonts/eicons.eot?5.14.0 .... )

Critical CSS translates that url() to
https://www.mysite.com/fonts/eicons.woff2?5.14.0

It also occurs with any other font URL in the CSS file.

I run this code for generating critical:
Crittr({ urls: [url], device: { scaleFactor: 2, width: 3050, height: 2000, }, pageLoadTimeout: 5000 }) .then(({critical, rest}) => { fs.writeFileSync(output, critical, 'utf-8'); }) .catch(err => { console.error(err); });

The problem is when the font url is bad, gtmetrix speed test has 302 redirects because of the bad url.
https://jmp.sh/eiSaPh0

@philipp-winterle philipp-winterle self-assigned this Sep 17, 2022
@philipp-winterle philipp-winterle added bug Something isn't working good first issue Good for newcomers labels Sep 17, 2022
@philipp-winterle philipp-winterle added this to the 1.6.0 milestone Sep 17, 2022
@Creativico
Copy link
Author

@hummal Sorry, I have just verified that elementor sometimes uses absolute path, sometimes relative path to fonts and in cases when it's relative then critical CSS fails. With absolute path works perfect in all conditions.

Also, thanks for your great work! :)

@philipp-winterle
Copy link
Owner

philipp-winterle commented Sep 17, 2022

Thank you for reaching me out!

So does this mean this is not a crittr issue?

As far as I understand this still happens if you have relative font urls?

Can you give a specific example to help me understand better?

@Creativico
Copy link
Author

@hummal So I believe this is a crittr issue because for example the file locations is:
www.whatever.com/wp-content/plugins/elementor/assets/lib/eicons/css/elementor-icons.min.css?ver=5.14.0
And it's has contents as relative url to font
@font-face{font-family:eicons;src:url(../fonts/eicons.eot?5.14.0);src:url(../fonts/eicons.eot?5.14.0#iefix) format("embedded-opentype")

Example:
https://jmp.sh/PuaXMbM

So once that is parsed into critical css and inserted into the page as inline critical css the path stays relative
url(../fonts/eicons.eot?5.14.0);

and in that case it translates in browser into bad url
www.whatever.com/fonts/eicons.eot?5.14.0

While the correct url would be
www.whatever.com/wp-content/plugins/elementor/assets/lib/eicons/fonts/eicons.eot?5.14.0

So in this case if you have any relative url it will not work unless the css file and fonts are in root of the site.

@philipp-winterle
Copy link
Owner

I guess there is a misunderstanding in how crittr is working. It only parses the outout on the website. If the css contains already the right paths it only uses these paths and put them into the critical css. There is no changing of paths because if the original css already contains the wrong paths crittr is not responsible for fixing those paths.

@philipp-winterle philipp-winterle added invalid This doesn't seem right and removed bug Something isn't working good first issue Good for newcomers labels Apr 10, 2023
@philipp-winterle philipp-winterle removed this from the 1.6.0 milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants