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

create an svg icon sprite for all action icons #3385

Closed
wants to merge 7 commits into from

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Feb 6, 2017

This should decrease the number of requests we need for (initial) page loads, ref ref #2272

doc https://github.com/jkphl/svg-sprite/blob/master/docs/configuration.md
Fixes https://github.com/jkphl/svg-sprite/blob/master/docs/configuration.md

Ideally, we should do this step-by-step because this change could potentially break stuff, especially in third-party apps. Therefore I will limit this PR to the basic setup (Grunt+config) and one example, the action icons. Other icons can be converted in follow-up PRs.


Follow-up idea/PR: use grunt+uglify to combine vendor scripts which are loaded on every page (jQuery, jQuery migrate, jQuery ui, Backbone, es6promise, …).

cc @nextcloud/designers
fixes #1066

@ChristophWurst ChristophWurst added 2. developing Work in progress design Design, UI, UX, etc. enhancement labels Feb 6, 2017
@ChristophWurst ChristophWurst added this to the Nextcloud 12.0 milestone Feb 6, 2017
@mention-bot
Copy link

@ChristophWurst, thanks for your PR! By analyzing the history of the files in this pull request, we identified @skjnldsv, @rullzer and @MorrisJobke to be potential reviewers.

@skjnldsv
Copy link
Member

skjnldsv commented Feb 6, 2017

Couldn't we generate it?

@ChristophWurst
Copy link
Member Author

Couldn't we generate it?

Generate what? :-)

@skjnldsv
Copy link
Member

skjnldsv commented Feb 6, 2017

The svg sprite! From the original sprites! ^^
I don't know if that was what you implied 😆

grunt.loadNpmTasks('grunt-svg-sprite');

grunt.registerTask('default', ['svg_sprite']);
};
Copy link
Member

Choose a reason for hiding this comment

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

I would really love to have a make file for this, that takes care of installing grunt and calling the right binaries, etc ... I don't want to fiddle around how to install it and which version and what the command then is.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add one ofc

@ChristophWurst
Copy link
Member Author

@skjnldsv yes, this PR is about combining multiple svg icons into an image sprite to speed up our front-end a bit :-)

@nickvergessen
Copy link
Member

Hmm but we can't really drop the original svgs as they are used by other apps (e.g. activity/notifications) and are even linked to, so apps can use them. For these cases we need the "single icon per file" version as a fallback anyway.

But should help to reduce the number of requests until one of the apps is used.

@skjnldsv
Copy link
Member

skjnldsv commented Feb 9, 2017

One more issue though is the background. Using a sprite as an icon with a recurrent width is easy, but since we use it for various elements tat sometimes are very large , we need to have each sprite very far from each others :)

@ChristophWurst
Copy link
Member Author

One more issue though is the background. Using a sprite as an icon with a recurrent width is easy, but since we use it for various elements tat sometimes are very large , we need to have each sprite very far from each others :)

I think that's probably the source of most of the problems I have found so far (see the list above).

@skjnldsv
Copy link
Member

skjnldsv commented Feb 9, 2017

Well, to be fair, the number of svg by px² shouldn't change the weight of the file.
And our goal is the number of requests, not as important of the weight imho :)

@nickvergessen
Copy link
Member

We can also have a look towards HTTP2 instead of this. Then the number of requests dont matter that much anymore...

@skjnldsv
Copy link
Member

skjnldsv commented Feb 9, 2017

We could also go for base64 encoded svg inside the compiled scss :)

@ChristophWurst
Copy link
Member Author

We can also have a look towards HTTP2 instead of this. Then the number of requests dont matter that much anymore...

In which regard would HTTPS2 help here?

@skjnldsv
Copy link
Member

skjnldsv commented Feb 9, 2017

Pipelining? Will send all the data all-at-once avoiding the cost of using sprites.

@ChristophWurst
Copy link
Member Author

@nickvergessen @skjnldsv did you try nc with HTTPS2? I gave it a test run a few months ago and I could not really see the huge benefit. I think we still load far too many files (~200 request per page load).

Related: http://stackoverflow.com/questions/28630108/does-minifying-and-concatenating-js-css-files-and-using-sprites-for-images-stil#28631462

@nickvergessen
Copy link
Member

I could not really see the huge benefit

Well yes, because we don't use it yet.

@ChristophWurst
Copy link
Member Author

ChristophWurst commented Feb 9, 2017

Well yes, because we don't use it yet.

How can we be not using that HTTP2 feature? It's nothing the site would have to enable, would it?

Edit: In any case, this still is a big problem. I just tested it again with nginx+TLS+http2, immutable cache and FF: it takes the browser a few seconds to even load those many assets from cache, you can track it in the network tab. Therefore, I am convinced that HTTP2 will not magically solve the performance problems we're facing on the client side, unfortunately.

@nickvergessen
Copy link
Member

Well we can add async attributes to JS and css files, etc. I didn't look too much into it.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst
Copy link
Member Author

Well, to be fair, the number of svg by px² shouldn't change the weight of the file.
And our goal is the number of requests, not as important of the weight imho :)

I've added 100px spacing in between the individual SVGs following the discussion at svg-sprite/svg-sprite#200 (comment).

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst
Copy link
Member Author

Okay, so now with the correct spacing less stuff looks broken, although still many icons are either not shown at all (e.g. the new folder icon in the files app) or are misplaced (e.g. the import button in calendar where the background position is manipulated by the app).

@jancborchardt
Copy link
Member

@ChristophWurst Do we have any issues or questions relating to the SVG sprite tool? Then let’s work with @jkphl to fix it :)

@ChristophWurst
Copy link
Member Author

@jancborchardt so far it seems to work. The problem here is our existing css 😉

@jkphl
Copy link

jkphl commented Feb 21, 2017

@jancborchardt @ChristophWurst Unfortunately, my spare time is very limited these days, but if you guys need help with svg-sprite please let me know and I'll do my best.

@MorrisJobke
Copy link
Member

@jancborchardt so far it seems to work. The problem here is our existing css 😉

Okay ... then we maybe look into fixing this and go for the sprite approach. No need to delay it further. 😉 I want to get this in quite fast to have more potential testers :)

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst
Copy link
Member Author

Fixed yet another issue with icons in popover menus. I'm not sure if I missed something, but this looks almost good to me. All the remaining issues seem to be inside apps, mostly because they overwrite the background position for stuff like the new mail/contact button:
bildschirmfoto von 2017-02-28 09-55-27

cc @nextcloud/calendar @nextcloud/contacts @nextcloud/gallery

@codecov-io
Copy link

Codecov Report

Merging #3385 into master will increase coverage by 0.18%.
The diff coverage is 33.33%.

@@             Coverage Diff              @@
##             master    #3385      +/-   ##
============================================
+ Coverage     54.28%   54.47%   +0.18%     
- Complexity    21061    21323     +262     
============================================
  Files          1310     1311       +1     
  Lines         80354    81931    +1577     
  Branches       1250     1367     +117     
============================================
+ Hits          43621    44629    +1008     
- Misses        36733    37302     +569
Impacted Files Coverage Δ Complexity Δ
core/templates/layout.user.php 0% <0%> (ø) 0 <0> (ø)
lib/private/legacy/template.php 45.02% <100%> (+0.32%) 35 <0> (ø)
lib/private/Setup.php 11.55% <0%> (-1.46%) 59% <0%> (+10%)
settings/js/apps.js 27.88% <0%> (-0.79%) 0% <0%> (ø)
config/config.sample.php 0% <0%> (ø) 0% <0%> (ø)
lib/private/Template/JSConfigHelper.php 0% <0%> (ø) 16% <0%> (ø)
lib/private/TemplateLayout.php 0% <0%> (ø) 38% <0%> (+6%)
ocs/v1.php 0% <0%> (ø) 0% <0%> (ø)
core/register_command.php 0% <0%> (ø) 0% <0%> (ø)
public.php 0% <0%> (ø) 0% <0%> (ø)
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d754227...8f3e5f7. Read the comment docs.

@@ -684,8 +684,6 @@ em {
/* Keep padding to define the width to
assure correct position of a possible text */
margin: 14px 13px 15px 16px;
min-width: 0; /* Overwrite icons*/
Copy link
Member

@skjnldsv skjnldsv Feb 28, 2017

Choose a reason for hiding this comment

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

This was used to cancel the min height/width applied to the icons. Since we're using padding to define the height, we don't want the 16x16px minimum set on [class^='icon-'], [class*=' icon-']

@ChristophWurst
Copy link
Member Author

I don't really know how to properly implement this without breaking too much. If someone wants to take over, please do so, otherwise I would close this.

@ChristophWurst ChristophWurst added 1. to develop Accepted and waiting to be taken care of and removed 2. developing Work in progress labels Mar 20, 2017
@MorrisJobke MorrisJobke mentioned this pull request Mar 28, 2017
3 tasks
@MorrisJobke
Copy link
Member

Alternative approach: #4059

@rullzer
Copy link
Member

rullzer commented Apr 4, 2017

Lets close this as it breaks to much. It should be cached anyways.

@rullzer rullzer closed this Apr 4, 2017
@rullzer
Copy link
Member

rullzer commented Apr 4, 2017

Feel free to reopen when somebody feels motivated.

@rullzer rullzer deleted the svg-sprites branch April 4, 2017 17:17
@jancborchardt
Copy link
Member

Referencing the issue about it: #1066 just for the record :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of design Design, UI, UX, etc. enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize load times of images & icons
9 participants