javascript - Why is next.js Image component not converting the svg to .webp file? - Stack Overflow

ContextSo I created a simple Hero + Navbar in Next.js. I use next.js Image ponent. On all my images on

Context

So I created a simple Hero + Navbar in Next.js. I use next.js Image ponent. On all my images on the site (i think 3 in total) the size is 0B and gets loaded instantly. They are of type .webp - so next.js image did convert these files.

The problem

In the navbar I have my logo which is a SVG of 2KB. I used this the same way I used the other .png files, but this time it's a .svg In the browser the file doesn't shrink and it's still a type of .svg and not .webp. Why is that?

Here is a screenshot how I use it:

Here is the network tab (filtered on images).

I import the svg file in the page like this import logoDark from "../public/assets/Logon New.svg"

Am I doing something wrong? Why is next.js not making a very fast .webp?

Thank you very much

Context

So I created a simple Hero + Navbar in Next.js. I use next.js Image ponent. On all my images on the site (i think 3 in total) the size is 0B and gets loaded instantly. They are of type .webp - so next.js image did convert these files.

The problem

In the navbar I have my logo which is a SVG of 2KB. I used this the same way I used the other .png files, but this time it's a .svg In the browser the file doesn't shrink and it's still a type of .svg and not .webp. Why is that?

Here is a screenshot how I use it:

Here is the network tab (filtered on images).

I import the svg file in the page like this import logoDark from "../public/assets/Logon New.svg"

Am I doing something wrong? Why is next.js not making a very fast .webp?

Thank you very much

Share Improve this question asked Aug 3, 2022 at 13:13 Dominik HuberDominik Huber 1252 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Multi-part answer:

Why you do not need SVG's further optimized

There is no need to take SVG's and convert them to a raster format. Vector format's are usually optimal and offer lossless scaling unless desktop programs added more meta data and bloated the file - even this can be rectified using tools like https://jakearchibald.github.io/svgomg/

next/image leaving SVG’s unoptimized:

The documentation shows why svg files are left alone

The default loader does not optimize SVG images for a few reasons. First, SVG is a vector format meaning it can be resized losslessly. Second, SVG has many of the same features as HTML/CSS, which can lead to vulnerabilities without proper Content Security Policy (CSP) headers.

If you need to serve SVG images with the default Image Optimization API, you can set dangerouslyAllowSVG and contentSecurityPolicy inside your next.config.js:

https://nextjs/docs/api-reference/next/image#dangerously-allow-svg

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745141284a4613443.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信