-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcache_longer.js
More file actions
35 lines (30 loc) · 1.11 KB
/
cache_longer.js
File metadata and controls
35 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
console.log("Loading Cache Longer");
browser.webRequest.onHeadersReceived.addListener(
function(details) {
var expires_found = false;
var cache_control_found = false;
var d = new Date();
d.setMonth(d.getMonth() + 6);
new_expires = d.toUTCString(); //6 months in the future
for (var header of details.responseHeaders) {
if (header.name.toLowerCase() === 'expires') {
header.value = new_expires;
expires_found = true;
}
if (header.name.toLowerCase() === 'cache-control') {
header.value = 'public, max-age=15780000'; //6 months
cache_control_found = true;
}
}
if(!expires_found) {
// If we are here, we didn't find any existing matching header.
details.responseHeaders.push({name: "Expires", value: new_expires });
}
if(!cache_control_found) {
details.responseHeaders.push({name: "Cache-Control", value: 'public, max-age=15780000' });
}
return { responseHeaders: details.responseHeaders };
},
{ urls: ["<all_urls>"], types: ["font", "image", "script", "stylesheet"] },
["blocking", "responseHeaders"]
);