Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Only attempt to cache GET requests
Browse files Browse the repository at this point in the history
Caching other types of request is prohibited by the spec.

Closes #10
  • Loading branch information
wibblymat committed Jun 3, 2015
1 parent c6baaa2 commit 4bb1715
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var globalOptions = require('./options');

function debug(message, options) {
options = options || {};
var flag = options.debug || globalOptions.debug;
var flag = options.debug || globalOptions.debug;
if (flag) {
console.log('[sw-toolbox] ' + message);
}
Expand All @@ -34,11 +34,11 @@ function openCache(options) {

function fetchAndCache(request, options) {
options = options || {};
var successResponses = options.successResponses || globalOptions.successResponses;
var successResponses = options.successResponses || globalOptions.successResponses;
return fetch(request.clone()).then(function(response) {

// Only cache successful responses
if (successResponses.test(response.status)) {
// Only cache GET requests with successful responses
if (request.method === 'GET' && successResponses.test(response.status)) {
openCache(options).then(function(cache) {
cache.put(request, response);
});
Expand Down Expand Up @@ -76,4 +76,4 @@ module.exports = {
fetchAndCache: fetchAndCache,
openCache: openCache,
renameCache: renameCache
};
};

0 comments on commit 4bb1715

Please sign in to comment.