Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Breaking Up with SVG-in-JS
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
wakamaki
July 28, 2023
Programming
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Breaking Up with SVG-in-JS
HRBrain Fly High #4 -Frontend-にて使用した資料
wakamaki
July 28, 2023
Other Decks in Programming
See All in Programming
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.3k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
270
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
170
ChromeでローカルLLM
ryu1013
0
150
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
3
630
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
220
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
510
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
730
dotNET_vulnclicker_intro.pdf
deka_morita
0
150
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
340
Workers Cache を知る
syumai
0
370
APNsからLive Activityを開始する話
yumnumm
0
170
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Site-Speed That Sticks
csswizardry
13
1.6k
A designer walks into a library…
pauljervisheath
211
25k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
430
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
How to make the Groovebox
asonas
2
2.5k
Transcript
Breaking Up with SVG-in-JS
自己紹介 大学 法政大学経済学部 4年 趣味 サウナ、キーボード
はじめに kurtextremさんのBreaking Up with SVG-in-JS in 2023 という記事の内容を参考にさせていただきました https://kurtextrem.de/posts/svg-in-js
Background
これまでのSVG-in-JSの扱い方
<!-- Icon.svg --> <svg viewBox="0 0 300 300"> <g><path d="M0
200 v-200 h200 a100,100 90 0,1 0,200 a100,100 90 0,1 -200,0z" /></g> </svg> import React from 'react'; import Icon from "./Icon.svg"; const Test = () => { return <Icon /> }
import * as React from "react" const Svg = (props)
=> ( <svg viewBox="0 0 300 300" width="1em" height="1em" {...props}> <path d="M0 200V0h200a100 100 90 0 1 0 200 100 100 90 0 1-200 0z" /> </svg> ) export default Svg import React from 'react'; import Svg from ".svg"; const Test = () => { return <Svg fill="red" width={20} height={20} /> } SVGR
なぜ SVG-in-JS はアンチパターンなのか
SVG要素は、Javascriptコードの一部として存在することがある バンドルサイズが大きくなるほど、Javascriptが パースとコンパイルにかけるコストが大きくなる。 大量のSVG要素が読み込まれる場合、パフォーマンスに影響 パース&コンパイル
SVG-in-JS SVG-in-HTML SVGがReactコンポーネントとして 存在するため、 Reactのレンダリングプロセスに 含まれる SVGは直接HTMLに含まれるため、 Reactのレンダリングプロセスに含まな い レンダリング
JS bundle から SVGs を取り除くベストプラクティス
<!-- Icon.svg --> <svg viewBox="0 0 300 300"> <g><path d="M0
200 v-200 h200 a100,100 90 0,1 0,200 a100,100 90 0,1 -200,0z" /></g> </svg> import React from 'react'; import Icon from "./Icon.svg"; const Test = () => { return <img src={Icon} /> } Using <img> to load the SVG
パフォーマンス vs ユーザーエクスペリエンス imgタグを使用する方法 • ページが最初にダウンロードされたときに、 アイコンのレンダリングで、ちらつきが生じる • CSSを使ってスタイルを設定できない
SVG sprites – using <use> <svg style="display: none;"> <symbol id="icon-heart"
viewBox="0 0 32 32"> <title>heart icon</title> <path d="M16 29.414l-13.413-13.415 6.826-6.826 6.587 6.587 6.587-6.587 6.8266.826z"></path> </symbol> </svg> <svg class="icon icon-heart"><use href="#icon-heart"></use></svg> <svg class="icon icon-heart"><use href="#icon-heart"></use></svg>
SVG sprites – using <use> メモリ使用量の削減: SVGスプライトと<use>要素を使用すると、 一つのSVGイメージを定義し、その定義を再利用して 同じイメージを複数の場所で表示することができる。 メモリ使用量が削減される。
SVG sprites – using <use> JavaScriptバンドルのサイズ削減: SVGスプライトを使用すると、SVGイメージは JavaScriptバンドルの一部ではなく、 独立したSVGファイルとして存在する。 JavaScriptバンドルのサイズが削減される。
SVG sprites – using <use> レンダリングパフォーマンスの向上: JavaScriptエンジンではなく ブラウザのHTMLパーサーとSVGレンダリングエンジン によってパースとレンダリングが行われる。 これはJavaScriptエンジンによるパースとレンダリングよりも効率
的で、レンダリングパフォーマンスが向上する。
環境にもよりますが、、 SVG sprites – using <use> を使うのが良さそう
まとめ SVG-in-JSは、パフォーマンスとメモリ使用量の観点から見るとアンチパターンである。 SVG-in-HTMLは、Javascriptバンドルサイズを小さくするための最善の方法。 ただし、 最適化すべきもっと重要なことがあるかもしれません。SVG最適化の前に、SVG-in-JSが最大の原 因ではないかもしれないことを心に留めておいてください。
ありがとうございました