Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Opaque vs Basic Handler Response
var url = '/scripts/main.min.c18e3e78.js';
var opaqueResponsePromise = function(response) {
console.log('opaque repsonse', response);
// Cache opaque response
var basicResponsePromise = function(response) {
console.log('basic repsonse');
// Parse the response
if(response.status !== 200) {
throw new Error('Bad status code');
return response.text()
.then(function(text) {
console.log('Response.text is complete');
.catch(function(err) {
console.log('Oops = ', err);
fetch(url, {'mode': 'cors'})
.then(function(response) {
if (response.type === 'opaque') {
console.log('The Response is opaque so we can\'t examine it');
// Do something with the response (i.e. cache it for offline support)
return opaqueResponsePromise(response);
return basicResponsePromise(response);
.catch(function(err) {
console.error('Fetch Error :-S', err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.