0

I have a project in Angular1.x using a lot of SVG files.

I have no idea what to do to SVG files to prepare them for production.

I don't want my page to invoke 50 calls to different SVG files. So what are my options and which tools do I have to accomplish them?

I use npm scripts to build my project.

closed as unclear what you're asking by Robert Harvey, gnat, Erik Eidt, Kilian Foth, user22815 Nov 28 '16 at 16:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Aren't those SVG files going to be cached in the browser anyway, the first time someone surfs your page? This is sort of how browsers work anyway; if you have 50 graphics on the page, that's going to cost you 50 web calls. – Robert Harvey Nov 27 '16 at 19:10
  • @RobertHarvey, html files I can use html2js, and save yet another call to every templateUrl in the project. Some svg files can be transformed to font. I am sure there are stuff I can do with svg files that have to remain as svg. – guy mograbi Nov 27 '16 at 19:42
  • css-tricks.com/… – Robert Harvey Nov 27 '16 at 19:43
  • @RobertHarvey - isn't this article for the person creating the SVGs? I just have to bundle everything for production and use it in the code. Are there no optimiziations on my side? I saw I can inline the svg, or create a sprite. some places suggest angular's ng-include.. I'm still trying to figure out which is the best way to go. – guy mograbi Nov 27 '16 at 20:25
  • 2
    What "best" means for you? That's a question nobody here can answer. You know what "you don't want", but what about "what you want"? – Laiv Nov 28 '16 at 7:20
3

You handle SVG files the same way you'd handle other web assets:

  1. In your build process, optimize ("minify") the files so they do not needlessly consume extra space or bandwidth. Tools like svgo do this trick. And there are already easy integrations into many build chains, such as gulp.

  2. Store them, if possible, on a content delivery network so that clients requesting these files hit a large, scalable network and storage resource, not your server. There is a cost to this, but generally a much lower one that serving all those HTTP GET requests from your main web server. (This step is highly, highly, ever so highly recommended for all image and other static assets; it often leads to large improvements in site load latency and site scalability.)

  3. You can consider bundling them, either embedded within HTML files, or in a data file such as a JSON resource. There is, however, no "one size fits all" bundling strategy. It depends on the size of the files and how they are used. Embedding/bundling strategies are usually not a transparent, trivial step. Finally, if you minify and CDN-offload the assets, the need for bundling is generally much reduced. If you do decide bundling is the way to go, look to your existing production packaging system. Tools like webpack often support specific bundling options, such as data URIs.

  4. Finally, consider SVG bundling as a refinement, to be handled after other build-process and packaging issues are solved and sorted. Your site can run just fine with a lot of image requests, and there are easy ways to optimize image requests (e.g. CDN offloading). The issues surrounding the rest of the build pipeline IME dwarf the issues associated with SVG per se. Get your horse and buggy in operation before worrying about how neatly trimmed the buggy is.

  • 1
    +1 to CDN approach. It also helps with versioning assets. Plus no more repeated assets all across your projects – Laiv Nov 28 '16 at 7:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.