Skip to content

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

Merged
MorrisJobke merged 4 commits into
masterfrom
wip/noid/icon-base64
Oct 25, 2018
Merged

MorrisJobke merged 4 commits into
masterfrom
wip/noid/icon-base64

Conversation

@juliusknorr

@juliusknorr juliusknorr commented Oct 24, 2018 •

Copy link
Copy Markdown
Member

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.

Comment thread lib/private/Template/IconsCacher.php Outdated
Comment thread lib/private/Template/IconsCacher.php Outdated
Comment thread lib/private/Template/IconsCacher.php Outdated
$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
Copy Markdown
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?

@juliusknorr

Copy link
Copy Markdown
Member Author

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

@juliusknorr

juliusknorr commented Oct 24, 2018 •

Copy link
Copy Markdown
Member Author
  • Fix accessibility dark theme icons

@MorrisJobke

This comment has been minimized.

@MorrisJobke

Copy link
Copy Markdown
Member

Chrome somehow shows the old assets

Cleared caches again and now it works also in chrome.

@rullzer

rullzer commented Oct 24, 2018

Copy link
Copy Markdown
Member

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

@skjnldsv

Copy link
Copy Markdown
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? 🤔

@juliusknorr

Copy link
Copy Markdown
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
Copy Markdown
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 :)

@juliusknorr

Copy link
Copy Markdown
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
Copy Markdown
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? :)

@juliusknorr

Copy link
Copy Markdown
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

@juliusknorr

Copy link
Copy Markdown
Member Author

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

@MorrisJobke

Copy link
Copy Markdown
Member

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

On it already ;)

@skjnldsv

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

@juliusknorr

Copy link
Copy Markdown
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
Copy Markdown
Member

You rocks @juliushaertl !! 🎸 🎉

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

@MorrisJobke MorrisJobke left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

@MorrisJobke

Copy link
Copy Markdown
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
@juliusknorr

Copy link
Copy Markdown
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
Copy Markdown
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