Semantic-Org/Semantic-UI · warning

Caching responses locally requires session storage

Error message

Caching responses locally requires session storage

What it means

This error is logged by the API module's read.cachedResponse() (api.js:144-146) and write.cachedResponse() (api.js:160-162) functions when settings.cache is set to 'local' (requesting sessionStorage-based caching) but window.Storage is undefined. window.Storage is the browser's built-in interface for sessionStorage and localStorage; if it is unavailable, the module cannot cache or retrieve responses locally.

Source

Thrown at src/definitions/behaviors/api.js:1137

  // request aborted
  onAbort     : function(errorMessage, $module) {},

  successTest : false,

  // errors
  error : {
    beforeSend        : 'The before send function has aborted the request',
    error             : 'There was an error with your request',
    exitConditions    : 'API Request Aborted. Exit conditions met',
    JSONParse         : 'JSON could not be parsed during error handling',
    legacyParameters  : 'You are using legacy API success callback names',
    method            : 'The method you called is not defined',
    missingAction     : 'API action used but no url was defined',
    missingSerialize  : 'jquery-serialize-object is required to add form data to an existing data object',
    missingURL        : 'No URL specified for api event',
    noReturnedValue   : 'The beforeSend callback must return a settings object, beforeSend ignored.',
    noStorage         : 'Caching responses locally requires session storage',
    parseError        : 'There was an error parsing your request',
    requiredParameter : 'Missing a required URL parameter: ',
    statusMessage     : 'Server gave an error: ',
    timeout           : 'Your request timed out'
  },

  regExp  : {
    required : /\{\$*[A-z0-9]+\}/g,
    optional : /\{\/\$*[A-z0-9]+\}/g,
  },

  className: {
    loading : 'loading',
    error   : 'error'
  },

  selector: {
    disabled : '.disabled',

View on GitHub (pinned to 597843ab84)

Solutions

  1. Use a different cache strategy: set settings.cache to false or 'browser' (relies on HTTP cache headers instead of sessionStorage).
  2. Wrap sessionStorage usage in a feature detection check before enabling cache: 'local'.
  3. Implement a fallback cache mechanism (e.g., in-memory Map) when sessionStorage is unavailable.

Example fix

// before
$('.el').api({
  url: '/api/data',
  cache: 'local'
  // fails in private browsing or sandboxed iframes
});

// after
var canCache = (function() {
  try { return window.Storage !== undefined; } catch(e) { return false; }
})();
$('.el').api({
  url: '/api/data',
  cache: canCache ? 'local' : false
});
Defensive patterns

Strategy: validation

Validate before calling

// Feature-detect sessionStorage before enabling local cache
var storageAvailable = (function() {
  try {
    var t = '__test__';
    sessionStorage.setItem(t, t);
    sessionStorage.removeItem(t);
    return true;
  } catch(e) { return false; }
})();
$('.el').api({
  cache: storageAvailable ? 'local' : false,
  url: '/api/data'
});

Type guard

// Check if sessionStorage is accessible
function isSessionStorageAvailable() {
  try { return window.Storage !== undefined && !!window.sessionStorage; }
  catch(e) { return false; }
}

Prevention

When it happens

Trigger: Configuring $('.el').api({ cache: 'local' }) in an environment where sessionStorage is not available. This occurs in private/incognito browsing modes in some older browsers, in Safari when cookies/storage are blocked, in embedded contexts (iframes with sandbox restrictions), or in server-side rendering environments where window and sessionStorage do not exist.

Common situations: Older browsers (IE7 and below) that lack sessionStorage. Safari with cross-site tracking prevention blocking storage in iframes. Headless browser testing environments (some configurations). Content Security Policy or sandbox attributes restricting storage access. Private browsing modes in mobile browsers.

Related errors


AI-assisted analysis of Semantic-Org/Semantic-UI@597843ab84 (2026-08-13). Data as JSON: /api/errors/46634896ae1a183c. Report an issue: GitHub.