Skip to content

Commit

Permalink
Preload svg icon sprite
Browse files Browse the repository at this point in the history
Preloading the svg icon sprite with `crossorigin` allowed should
fix CORS issues.

See https://oreillymedia.github.io/Using_SVG/extras/ch10-cors.html

Fixes #2937
  • Loading branch information
tvdeyen committed Sep 20, 2024
1 parent a7b3624 commit cbaeaf7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/javascript/alchemy_admin/components/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class Icon extends HTMLElement {
constructor() {
super()
this.spriteUrl = document
.querySelector('meta[name="alchemy-icon-sprite"]')
.getAttribute("content")
.querySelector('link[rel="preload"][as="image"]')
.getAttribute("href")
}

connectedCallback() {
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/alchemy_admin/shoelace_theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ setDefaultAnimation("dialog.hide", {
})

const spriteUrl = document
.querySelector('meta[name="alchemy-icon-sprite"]')
.getAttribute("content")
.querySelector('link[rel="preload"][as="image"]')
.getAttribute("href")

const iconMap = {
"x-lg": "close"
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><%= render_alchemy_title %></title>
<link rel="shortcut icon" href="<%= asset_path('alchemy/favicon.ico') %>">
<link rel="preload" href="<%= asset_path("remixicon.symbol.svg") %>" as="image" type="<%= Mime::Type.lookup_by_extension(:svg) %>" crossorigin>
<%= csrf_meta_tag %>
<meta name="robots" content="noindex">
<meta name="alchemy-icon-sprite" content="<%= asset_path("remixicon.symbol.svg") %>">
<meta name="turbo-prefetch" content="false">
<meta name="turbo-cache-control" content="no-cache">
<%= stylesheet_link_tag('alchemy/admin', media: 'screen', 'data-turbo-track' => true) %>
Expand Down

0 comments on commit cbaeaf7

Please sign in to comment.