Skip to content

Commit d706942

Browse files
committed
Fix trailing ? bug on removeCacheBust
1 parent afb33f9 commit d706942

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

public/reloader.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const removeCacheBust = (url) => {
2323
const [path, queryString] = url.split('?');
2424
const params = new URLSearchParams(queryString);
2525
params.delete(queryKey);
26-
return [path, params].join('?');
26+
return [path, params].join('?').replace(/\?$/g, '');
2727
};
2828
const addCacheBust = (url) => {
2929
const [path, queryString] = url.split('?');
@@ -39,14 +39,13 @@ const getUrlAttr = (elem) => (elem['src'] ? 'src' : 'href');
3939
// - link.src/link['src'] will return the computed property, ie "http://localhost/logo.svg"
4040
// - link.getAttribute('src') will return "logo.svg"
4141
const updateElems = (fileName) => {
42-
const elems = [...document.querySelectorAll('[href],[src]')].filter(
43-
(link) => {
44-
const attr = getUrlAttr(link);
45-
if (!link.getAttribute(attr)) return;
46-
// TODO(bret): this check isn't robust, esp once we add srcset support (and '../' could screw it up!)
47-
return removeAllQueryStrings(link[attr]).endsWith(fileName);
48-
},
49-
);
42+
const query = ':not(a):where([href],[src])';
43+
const elems = [...document.querySelectorAll(query)].filter((link) => {
44+
const attr = getUrlAttr(link);
45+
if (!link.getAttribute(attr)) return;
46+
// TODO(bret): this check isn't robust, esp once we add srcset support (and '../' could screw it up!)
47+
return removeAllQueryStrings(link[attr]).endsWith(fileName);
48+
});
5049

5150
elems.forEach((elem) => {
5251
const attr = getUrlAttr(elem);

0 commit comments

Comments
 (0)