var PREFIX = "dynamic-import:";
var ID_PREFIX = PREFIX + "id:";
var VERSION_PREFIX = PREFIX + "version:";
var MISSING_ERROR = new Error("version not found");
var pendingClean = null;

function getItem(key) {
  var value = Meteor._localStorage.getItem(key);
  return typeof value === "string"
    ? Promise.resolve(value)
    : Promise.reject(MISSING_ERROR);
}

function setItem(key, value) {
  Meteor._localStorage.setItem(key, value);
}

function clean() {
  clearTimeout(pendingClean);
  pendingClean = null;

  var activeVersions = Object.create(null);
  var allVersions = Object.create(null);

  Object.keys(Meteor._localStorage).forEach(function (key) {
    if (key.startsWith(ID_PREFIX)) {
      activeVersions[Meteor._localStorage.getItem(key)] = true;
    } else if (key.startsWith(VERSION_PREFIX)) {
      var version = key.slice(VERSION_PREFIX.length);
      allVersions[version] = key;
    }
  });

  Object.keys(allVersions).forEach(function (version) {
    if (activeVersions[version] !== true) {
      Meteor._localStorage.removeItem(allVersions[version]);
    }
  });
}

exports.check = function check(id, currentVersion) {
  return getItem(ID_PREFIX + id).then(function (previousVersion) {
    if (currentVersion === previousVersion) {
      return getItem(VERSION_PREFIX + previousVersion);
    }
    throw MISSING_ERROR;
  });
};

exports.set = function set(id, version, value) {
  if (! pendingClean) {
    pendingClean = setTimeout(clean, 1000);
  }

  return Promise.all([
    setItem(VERSION_PREFIX + version, value),
    setItem(ID_PREFIX + id, version)
  ]);
};

@@ -95,24 +95,58 @@
 %22version:%22;%0A
+var RESOLVED = Promise.resolve();%0A
 var MISSING_
@@ -185,16 +185,130 @@
 ound%22);%0A
+var MISSING = Promise.reject(MISSING_ERROR);%0A// Silence uncaught rejection warnings.%0AMISSING.catch(function()%7B%7D);%0A
 var pend
@@ -472,37 +472,15 @@
   : 
-Promise.reject(MISSING_ERROR)
+MISSING
 ;%0A%7D%0A
@@ -1258,16 +1258,72 @@
 sion) %7B%0A
+  if (! Meteor.isProduction) %7B%0A    return MISSING;%0A  %7D%0A%0A
   return
@@ -1385,20 +1385,23 @@
 ) %7B%0A    
-if (
+return 
 currentV
@@ -1430,24 +1430,16 @@
 sion
-) %7B
 %0A      
-return
+?
  get
@@ -1480,33 +1480,24 @@
 ion)
-;
 %0A    
-%7D%0A    throw
+  :
  MISSING
 _ERR
@@ -1492,22 +1492,16 @@
  MISSING
-_ERROR
 ;%0A  %7D);%0A
@@ -1549,24 +1549,81 @@
 n, value) %7B%0A
+  if (! Meteor.isProduction) %7B%0A    return RESOLVED;%0A  %7D%0A%0A
   if (! pend

Use Meteor._localStorage only in production mode.