Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor file hash extraction without query string #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,21 @@ self.addEventListener('fetch', (event) => {
});

function removeHash(element) {
if (typeof element === 'string') return element.split('?hash=')[0];
if (typeof element === 'string') {
var url = new URL(element);
return url.pathname.replace(".js", "").replace(".css", "").replace("/", "");
}
}

function hasHash(element) {
if (typeof element === 'string') return /\?hash=.*/.test(element);
if (typeof element === 'string') return /\?meteor_js_resource=true|meteor_css_resource=true.*/.test(element);
}

function hasSameHash(firstUrl, secondUrl) {
if (typeof firstUrl === 'string' && typeof secondUrl === 'string') {
return /\?hash=(.*)/.exec(firstUrl)[1] === /\?hash=(.*)/.exec(secondUrl)[1];
var first = new URL(firstUrl).pathname.replace(".js", "").replace(".css", "").replace("/", "");
var last = new URL(secondUrl).pathname.replace(".js", "").replace(".css", "").replace("/", "");
return first === last;
}
}

Expand Down