pragma-no-cache-with-cache-control.html (2359B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTTP Cache: Cache-Control with Pragma: no-cache</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <body> 7 <script> 8 promise_test(async _t => { 9 // According to https://www.rfc-editor.org/rfc/rfc9111.html#name-pragma 10 // the pragma header is deprecated. 11 // When there's a mismatch between pragma and Cache-Control then the latter 12 // should be respected, and the resource should be cached, but this could 13 // lead to web-compat issues when one browser caches and others don't. 14 // It's safer to avoid caching when Pragma: no-cache is present, even though 15 // this further ossifies its use. 16 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1937766 and 17 // https://issues.chromium.org/issues/447171250 for discussion. 18 const url = 'resources/cached_pragma_rand.py' 19 20 // First fetch to populate the cache 21 const response1 = await fetch(url, { cache: 'default' }); 22 assert_true(response1.ok, 'First fetch should succeed'); 23 const text1 = await response1.text(); 24 25 // Second fetch should be served from cache 26 const response2 = await fetch(url, { cache: 'default' }); 27 assert_true(response2.ok, 'Second fetch should succeed'); 28 const text2 = await response2.text(); 29 30 assert_not_equals(text1, text2, 'Responses should be different, indicating no cache use'); 31 }, 'Response with Cache-Control: max-age=2592000, public and Pragma: no-cache should not be cached'); 32 33 promise_test(async _t => { 34 // Cache-Control: immutable should be cached even when Pragma: no-cache is present 35 // because immutable is a strong directive indicating the resource will never change. 36 const url = 'resources/cached_pragma_immutable_rand.py' 37 38 // First fetch to populate the cache 39 const response1 = await fetch(url, { cache: 'default' }); 40 assert_true(response1.ok, 'First fetch should succeed'); 41 const text1 = await response1.text(); 42 43 // Second fetch should be served from cache 44 const response2 = await fetch(url, { cache: 'default' }); 45 assert_true(response2.ok, 'Second fetch should succeed'); 46 const text2 = await response2.text(); 47 48 assert_equals(text1, text2, 'Responses should be identical, indicating cache use'); 49 }, 'Response with Cache-Control: max-age=2592000, immutable and Pragma: no-cache should be cached'); 50 51 </script> 52 </body>