Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG images loading slow or last in site

Tags:

html

css

svg

I have a couple of SVG backgrounds on a site. Their size are less than 50kb, however, they load slow, or also, they seem to load as last element on the website. Since they are on the header of the page, I don't want a blank space while the image loads. I have been trying to find an answer or a reason to why this happens and optimize the svgs but can't seem to find a solution. My backgrounds are for about 2-3 secs white and then the SVGs appears.

I'm loading the SVG inline in CSS

This is what I have on my html

<div class='header-main'>
  <div class="header">
    <hr></hr>
    <h1 class="tagline">Some Text</h1>
  </div>
</div>

and the CSS loading the SVG is:

.header-main {
  background: url('{{ asset "/img/background-main.svg"}}');
}
like image 521
John R Avatar asked Sep 02 '17 05:09

John R


People also ask

Do SVG images load faster?

SVG code is loaded faster because there is no need for an HTTP request to load in an image file. The time taken for SVG code is only rendering time. There can be numerous editing and animating opportunities for SVG code like you said.

Does SVG slow down website?

Once the bloat is removed, the file size can decrease by a large amount, which speeds up your end user load speed, especially if you have lots of SVGs on a single page. This article will show you what to remove from your SVGs to stop them from slowing down your page and giving your end user a poor experience.

How do I make SVG run faster?

Use groups. Using groups to apply styles rather than applying styles to each path is a lossless optimisation that reduces file size (making the file faster to load), as well as improves render speed by allowing the web browser to better optimise drawing.

Do SVGs cause performance issues?

SVG is just XML markup, therefore it lends itself to compression without any issues. The benefits in terms of file reduction are significant. Appendix J of the SVG 1.1 Specification shows a comparison table between examples of uncompressed and compressed SVG files.


1 Answers

You could write the svg directly into the html. That would force it to be loaded along with the rest of the page.

like image 107
EKW Avatar answered Oct 02 '22 18:10

EKW