locizify 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 8.0.1
2
+
3
+ - update i18next-locize-backend
4
+
1
5
  ### 8.0.0
2
6
 
3
7
  - update i18next-locize-backend
package/README.md CHANGED
@@ -12,7 +12,7 @@ Just drop the following line to your header to deliver your content in any langu
12
12
  id="locizify"
13
13
  projectid="[PROJECT_ID]"
14
14
  apikey="[API_KEY]"
15
- src="https://unpkg.com/locizify@^7.0.3"
15
+ src="https://unpkg.com/locizify@^8.0.0"
16
16
  autopilot="true"
17
17
  cdnType="standard"
18
18
  ></script>
@@ -22,7 +22,7 @@ Just drop the following line to your header to deliver your content in any langu
22
22
  id="locizify"
23
23
  projectid="[PROJECT_ID]"
24
24
  apikey="[API_KEY]"
25
- src="https://cdn.jsdelivr.net/npm/locizify@^7.0.3"
25
+ src="https://cdn.jsdelivr.net/npm/locizify@^8.0.0"
26
26
  autopilot="true"
27
27
  cdnType="standard"
28
28
  ></script>
@@ -71,7 +71,7 @@ Add the script to your page:
71
71
  id="locizify"
72
72
  projectid="[PROJECT_ID]"
73
73
  apikey="[API_KEY]"
74
- src="https://unpkg.com/locizify@^7.0.3"
74
+ src="https://unpkg.com/locizify@^8.0.0"
75
75
  autopilot
76
76
  cdnType="standard"
77
77
  ></script>
@@ -105,7 +105,7 @@ Add the script to your page:
105
105
  apikey="[API_KEY]"
106
106
  referencelng="[LNG]"
107
107
  fallbacklng="[LNG]"
108
- src="https://unpkg.com/locizify@^7.0.3"
108
+ src="https://unpkg.com/locizify@^8.0.0"
109
109
 
110
110
  // all custom attributes can also be prefixed with data-
111
111
  // data-projectid="[PROJECT_ID]"
@@ -136,7 +136,7 @@ Add the script to your page:
136
136
  <!DOCTYPE html>
137
137
  <html>
138
138
  <head>
139
- <script src="https://unpkg.com/locizify@^7.0.3"></script>
139
+ <script src="https://unpkg.com/locizify@^8.0.0"></script>
140
140
  <script>
141
141
  locizify.init({
142
142
  // required
@@ -7260,6 +7260,12 @@
7260
7260
  }).catch(function () {});
7261
7261
  } catch (e) {}
7262
7262
  }
7263
+ var storage = {};
7264
+ var parseMaxAge = function parseMaxAge(headerString) {
7265
+ if (!headerString) return 0;
7266
+ var matches = headerString.match(/max-age=([0-9]+)/);
7267
+ return matches ? parseInt(matches[1], 10) : 0;
7268
+ };
7263
7269
  var requestWithFetch$1 = function requestWithFetch(options, url, payload, callback) {
7264
7270
  var headers = {};
7265
7271
  if (typeof window === 'undefined' && typeof global !== 'undefined' && typeof global.process !== 'undefined' && global.process.versions && global.process.versions.node) {
@@ -7285,11 +7291,13 @@
7285
7291
  status: response.status,
7286
7292
  resourceNotExisting: resourceNotExisting
7287
7293
  });
7294
+ var cacheControl = response.headers && response.headers.get('cache-control');
7288
7295
  response.text().then(function (data) {
7289
7296
  callback(null, {
7290
7297
  status: response.status,
7291
7298
  data: data,
7292
- resourceNotExisting: resourceNotExisting
7299
+ resourceNotExisting: resourceNotExisting,
7300
+ cacheControl: cacheControl
7293
7301
  });
7294
7302
  }).catch(callback);
7295
7303
  };
@@ -7330,10 +7338,12 @@
7330
7338
  resourceNotExisting: resourceNotExisting
7331
7339
  });
7332
7340
  }
7341
+ var cacheControl = x.getResponseHeader('Cache-Control');
7333
7342
  x.readyState > 3 && callback(x.status >= 400 ? x.statusText : null, {
7334
7343
  status: x.status,
7335
7344
  data: x.responseText,
7336
- resourceNotExisting: resourceNotExisting
7345
+ resourceNotExisting: resourceNotExisting,
7346
+ cacheControl: cacheControl
7337
7347
  });
7338
7348
  };
7339
7349
  x.send(JSON.stringify(payload));
@@ -7347,6 +7357,26 @@
7347
7357
  payload = undefined;
7348
7358
  }
7349
7359
  callback = callback || function () {};
7360
+ var useCacheLayer = typeof window === 'undefined' && options.useCacheLayer;
7361
+ if (useCacheLayer && !payload && !options.noCache && storage[url] && storage[url].expires > Date.now()) {
7362
+ return callback(null, storage[url].data);
7363
+ }
7364
+ var originalCallback = callback;
7365
+ callback = function callback(err, res) {
7366
+ if (useCacheLayer && !err && res && !payload && res.cacheControl) {
7367
+ var maxAge = parseMaxAge(res.cacheControl);
7368
+ if (maxAge > 0) {
7369
+ storage[url] = {
7370
+ data: res,
7371
+ expires: Date.now() + maxAge * 1000
7372
+ };
7373
+ }
7374
+ }
7375
+ originalCallback(err, res);
7376
+ };
7377
+ if (!payload && options.noCache && options.cdnType === 'standard') {
7378
+ url += (url.indexOf('?') >= 0 ? '&' : '?') + 'cache=no';
7379
+ }
7350
7380
  if (fetchApi$1) {
7351
7381
  return requestWithFetch$1(options, url, payload, callback);
7352
7382
  }
@@ -7420,7 +7450,8 @@
7420
7450
  reloadInterval: typeof window !== 'undefined' ? false : 60 * 60 * 1000,
7421
7451
  checkForProjectTimeout: 3 * 1000,
7422
7452
  storageExpiration: 60 * 60 * 1000,
7423
- writeDebounce: 5 * 1000
7453
+ writeDebounce: 5 * 1000,
7454
+ useCacheLayer: typeof window === 'undefined'
7424
7455
  }, getApiPaths(cdnType));
7425
7456
  };
7426
7457
  var hasLocalStorageSupport$1;