
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
xdlocalstorage
Advanced tools
As for now, standard HTML5 Web Storage (a.k.a Local Storage) doesn't now allow cross domain data sharing. This may be a big problem in an organization which have a lot of sub domains and wants to share client data between them.
xdLocalStorage is a lightweight js library which implements LocalStorage interface and support cross domain storage by using iframe post message communication.
Although cookies can be shared between sub domains, cookies have the overhead of being sent to the server on each request. They're also have a size limit (4K for all cookies together)
Download latest release from here or use bower/npm (recommended)
bower install xdLocalStorage --save
or
npm install --save xdlocalstorage
<!DOCTYPE html>
<html>
<head>
<script src="xdLocalStoragePostMessageApi.min.js"></script>
</head>
<body>
This is the magical iframe
</body>
</html>
<!-- if you use angular continue reading.. there's angular support -->
<script src="scripts/xdLocalStorage.min.js"></script>
xdLocalStorage.init(
{
/* required */
iframeUrl:'path to your html from step 1',
//an option function to be called right after the iframe was loaded and ready for action
initCallback: function () {
console.log('Got iframe ready');
}
}
);
// Store
xdLocalStorage.setItem(key, value, function (data) { /* callback */ });
// Retrieve
xdLocalStorage.getItem(key, function (data) { /* callback */ });
// Remove
xdLocalStorage.removeItem(key, function (data) { /* callback */ });
// Key Name
xdLocalStorage.key(index, function (data) { /* callback */ });
// Clear All
xdLocalStorage.clear(function (data) { /* callback */ });
UPDATE: Since version 2.0.0 the xdLocalStorage service supoprts promise interface hence no more annoying callbacks :)
import ng-xdLocalStorage.min.js
instead of xdLocalStorage.min.js
include xdLocalStorage module and call init in a run block.
angular.module('yourModule', ['xdLocalStorage']).run(function (xdLocalStorage) {
xdLocalStorage.init(
{
/* required */
iframeUrl:'path to your html from step 1'
}).then(function () {
//an option function to be called once the iframe was loaded and ready for action
console.log('Got iframe ready');
});
});
angular.module('yourModule').run(function(xdLocalStorage) {
xdLocalStorage.getItem(key).then(function (response) {
console.log(response.value);
});
});
Here's the demo
I covered the basic API with tests here
Apple has updated the defaults on Safari 7+ both on desktop and mobile to block 3rd party data. The option is now called "Block cookies and other website data" which refers to things like localstorage which are now completely isolated by domain.
This implies that unfortunately this library will not be able to share cross domain information on Safari 7+.
FAQs
Cross Domain Local Storage ==========================
We found that xdlocalstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.