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

Directly embed icons into the icon-vars css file #12016

Merged
merged 4 commits into from
Oct 25, 2018

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Oct 24, 2018

This is a PoC to directly embed SVG icons into the generated CSS files. While it will have some influence on the loading time of the first request (since every svg file is read then by the server) it drastically reduces requests and loading time later on.

The icons are added base64 encoded to the icon-vars.css.

I did some quick&rough measurements on a quite suboptimal setup (no redis, sqlite, modphp)

Before/After

  • First loading
    • Diabled browser cache 20s/20s
  • SCSS has been cached
    • Disabled browser cache 15s/5s
    • Enabled browser cache 3s/1.5s

Part of #1066

For testing you will need to run occ maintenance:repair to clear the scss cache.

Feedback is welcome. The code could need another cleanup before merging 🙈

cc @nextcloud/designers

@MorrisJobke

This comment has been minimized.

$svg = preg_replace('/stroke="#([a-z0-9]{3,6})"/mi', 'stroke="#' . $color . '"', $svg);
$svg = preg_replace('/fill="#([a-z0-9]{3,6})"/mi', 'fill="#' . $color . '"', $svg);

$encode = base64_encode($file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should $file be $svg?

@juliushaertl
Copy link
Member Author

@MorrisJobke Can you try again? Seems the regex needed an adjustment as well 🙈

@juliushaertl
Copy link
Member Author

juliushaertl commented Oct 24, 2018

  • Fix accessibility dark theme icons

@MorrisJobke

This comment has been minimized.

@MorrisJobke
Copy link
Member

Chrome somehow shows the old assets

Cleared caches again and now it works also in chrome.

@rullzer
Copy link
Member

rullzer commented Oct 24, 2018

Nice work.
Doing this makes me think. More and more we should start shipping pregenerated css.

@skjnldsv
Copy link
Member

It's very nice, but this goes directly against the idea of having a colour api, no? 🤷‍♀️
We don't fetch the data from the svg colour anymore, then? 🤔

@juliushaertl
Copy link
Member Author

Doing this makes me think. More and more we should start shipping pregenerated css.

I would totally support that. The main issue why we included all the SCSS compilation logic was, to lower the entry barrier. But now that we have more and more vue apps, we require a npm based dev environment anyway, so we could move towards a preprocessed css as well.

It's very nice, but this goes directly against the idea of having a colour api, no? woman_shrugging
We don't fetch the data from the svg colour anymore, then? thinking

Yes, when I started with this I thought about keeping the api for the accessibility app, but that one could of course also just replace the colors in the inline images then.

@skjnldsv
Copy link
Member

Yes, when I started with this I thought about keeping the api for the accessibility app, but that one could of course also just replace the colors in the inline images then.

I'm totally fine with the approach! But I would like to keep a way to still get colorized svg the way we do this :)

@juliushaertl
Copy link
Member Author

I'm totally fine with the approach! But I would like to keep a way to still get colorized svg the way we do this :)

@skjnldsv You mean to keep the svg endpoint, or just a way to change the svg color?

@skjnldsv
Copy link
Member

@skjnldsv You mean to keep the svg endpoint, or just a way to change the svg color?

Well both of them, having a way to sill colorized svg on the fly is very nice for devs I think? :)

Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl
Copy link
Member Author

Ready for review. The accessibility app still uses the svg api endpoint for now, since we don't cache the user css files on the server, this would increase the loading time with empty browser cache quite a bit. We still can do this in a follow up PR.

The flow of icons is now:

  • A scss file is compiled
  • The IconsCacher looks for --icon variables
    • it creates a icons-list.template file with the original links to the svg api for later processing
    • it creates a icons-vars.css file with the icons embedded as data url based on the icons-list.template
  • The accessibility app now also uses the icons-list.template to replace colors for inverted icons

@juliushaertl
Copy link
Member Author

@MorrisJobke Can you check if that also fixes the rerendering issue on safari?

@MorrisJobke
Copy link
Member

@MorrisJobke Can you check if that also fixes the rerendering issue on safari?

On it already ;)

@skjnldsv
Copy link
Member

@juliushaertl So just so I get this right, we can't directly get svg coloured anymore, BUT if we declare them via css it will work?

@MorrisJobke
Copy link
Member

@MorrisJobke Can you check if that also fixes the rerendering issue on safari?

Still re-renders everything. Only if the support icon is deleted from the page the re-rendering stops. 😢

@skjnldsv
Copy link
Member

@MorrisJobke Can you check if that also fixes the rerendering issue on safari?

Still re-renders everything. Only if the support icon is deleted from the page the re-rendering stops.

Yes, but still a lot better without the requests in the background!

@juliushaertl
Copy link
Member Author

So just so I get this right, we can't directly get svg coloured anymore, BUT if we declare them via css it will work?

Yes, All the mixins we have that use the icon-color mixin, will automatically be inlined. But fetching them from the svg endpoint would still work, in case apps use that.

@skjnldsv
Copy link
Member

You rocks @juliushaertl !! 🎸 🎉

@juliushaertl juliushaertl added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Oct 25, 2018
Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works over here 👍

@MorrisJobke
Copy link
Member

@juliushaertl Could you check the acceptance tests that fail? They look weird.

@MorrisJobke
Copy link
Member

I also triggered a re-run: https://drone.nextcloud.com/nextcloud/server/11850

@MorrisJobke MorrisJobke added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Oct 25, 2018
@juliushaertl
Copy link
Member Author

@MorrisJobke They run fine locally for me. files and user acceptance tests indrone.nextcloud.com/nextcloud/server/11850 timed out again it seems 😢

@MorrisJobke MorrisJobke merged commit 6ad7f32 into master Oct 25, 2018
@MorrisJobke MorrisJobke deleted the wip/noid/icon-base64 branch October 25, 2018 14:04
@jancborchardt
Copy link
Member

Wow @juliushaertl! Performance work always deserves praise! 🥇 :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants