SVGs have been around for years due to its scalability and it is long-familiar that the benefit of inline SVG is one can manipulate it with CSS and JS, and when we want to repeat the same SVG over a html document, then we can use the <use>
tag to reference the original element. Furthermore, inline SVGs could also reduce the number of HTTP requests.
However, many articles suggest (without explaining the details) that while we use inline SVG to save HTTP request, it is no longer cacheable by a browser as a separate subject, which means it is not reusable across the pages.
As I happen to use inline SVGs extensively for a project, I would like to know exactly how inline SVG (the renowned html5 element, which is a w3c recommendation) can be cached in browsers whilst using SVGs with <img>
tag or background-image
are cacheable.
If DOM is cacheable, then why can't the SVG DOM ?
(which builds upon and is compatible with DOM Level 2. Ref: https://www.w3.org/TR/SVG/svgdom.html)
So far, the solution I came up with cachebility is to use Data URI scheme
(Also Ref: Optimizing svgs in data uris )
But by doing so, it loses the ability to deal with CSS and JS for styling and manipulation.
A few examples around the web suggest the use of JS to load cacheable resource or by replacing placeholder elements such as <object>
tag, as well as using localStorage, CacheStorage and Service Worker. But I still need some guide lines to get started to achieve an ideal solution.
Could someone shed me some light please?
-
-
-
Ref: Caching SVG Sprite in localStorage
Ref: Inline SVG and caching
Ref: SVG ON THE WEB
Ref: Do Inline SVGs Weigh Down Websites?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…