From 6334e096bcc52b8707663585d6714406b378b4b4 Mon Sep 17 00:00:00 2001 From: Mike Naughton Date: Wed, 18 Nov 2015 10:30:54 -0600 Subject: [PATCH] Fix IE-related JSON caching issue. --- lib/responses/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/responses/index.js b/lib/responses/index.js index 45f1555..2f39709 100644 --- a/lib/responses/index.js +++ b/lib/responses/index.js @@ -102,6 +102,10 @@ module.exports.buildResponse = function (req, res, data, options, config) { // If appropriate, serve data as JSON(P) if (req.wantsJSON) { + res.header('Cache-Control', 'no-cache, max-age=0, maxage=0, no-store, must-revalidate'); + res.header('Pragma', 'no-cache'); + res.header('Expires', -1); + res.header('Pragma', 'no-store'); return res.jsonx(json); } @@ -121,6 +125,10 @@ module.exports.buildResponse = function (req, res, data, options, config) { else { if(config.isGuessView) { return res.guessView({ data: data }, function couldNotGuessView () { + res.header('Cache-Control', 'no-cache, max-age=0, maxage=0, no-store, must-revalidate'); + res.header('Pragma', 'no-cache'); + res.header('Expires', -1); + res.header('Pragma', 'no-store'); return res.jsonx(data); }); } else { @@ -138,6 +146,11 @@ module.exports.buildResponse = function (req, res, data, options, config) { else { sails.log.warn('res.'+config.name+'() :: When attempting to render error page view, an error occured (sending JSON instead). Details: ', err); } + + res.header('Cache-Control', 'no-cache, max-age=0, maxage=0, no-store, must-revalidate'); + res.header('Pragma', 'no-cache'); + res.header('Expires', -1); + res.header('Pragma', 'no-store'); return res.jsonx(data); }