Skip to content

Commit

Permalink
Fix caching problem when loading CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemanrubia committed Dec 5, 2024
1 parent 16a9d02 commit dd746d2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/hotwire_spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ var HotwireSpark = (function () {
return new Promise(resolve => {
const href = link.getAttribute("href");
const newLink = this.#findNewLinkFor(link);
newLink.href = cacheBustedUrl(newLink.href);
newLink.setAttribute("href", cacheBustedUrl(newLink.getAttribute("href")));
newLink.onload = () => {
log(`\t${href}`);
resolve();
Expand All @@ -3640,7 +3640,7 @@ var HotwireSpark = (function () {
});
}
#withoutAssetDigest(url) {
return url.replace(/-[^-]+\.css$/, ".css");
return url.replace(/-[^-]+\.css.*$/, ".css");
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/hotwire_spark.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/hotwire_spark.min.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions app/javascript/hotwire_spark/reloaders/css_reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export class CssReloader {
return new Promise(resolve => {
const href = link.getAttribute("href")
const newLink = this.#findNewLinkFor(link)

newLink.href = cacheBustedUrl(newLink.href)
newLink.setAttribute("href", cacheBustedUrl(newLink.getAttribute("href")))
newLink.onload = () => {
log(`\t${href}`)
resolve()
Expand All @@ -62,6 +61,6 @@ export class CssReloader {
}

#withoutAssetDigest(url) {
return url.replace(/-[^-]+\.css$/, ".css")
return url.replace(/-[^-]+\.css.*$/, ".css")
}
}

0 comments on commit dd746d2

Please sign in to comment.