npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cross-domain-local-storage-separately

v1.0.0

Published

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.

Downloads

1

Readme

Cross Domain Local Storage Separately

  1. Problem
  2. Solution
  3. Why not use cookies?
  4. Installation
  5. Usage
  6. API
  7. Angular Support
  8. Demo
  9. Tests
  10. Limitations

Problem

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.

Solution

xdLocalStorage is a lightweight js library which implements LocalStorage interface and support cross domain storage by using iframe post message communication independently.

Why not use cookies?

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)

Installation

Download latest release from here or use bower/npm (recommended)

bower install xdLocalStorage --save
or
npm install --save xdlocalstorage

Usage

  • Create an empty html with the following content:
<!DOCTYPE html>
<html>
<head>
    <script src="xdLocalStoragePostMessageApi.min.js"></script>
</head>
<body>
    This is the magical iframe
</body>
</html>
  • On your client page (the page you will read/store your data from) add:
 <!-- if you use angular continue reading.. there's angular support -->
 <script src="scripts/xdLocalStorage.min.js"></script>
  • Init xdLocalStorage
    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');
            }
        }
    );

API

    // 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 */ });

Angular Support

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');
    });
});
  • inject xdLocalStorage where ever you want and use the API
angular.module('yourModule').run(function(xdLocalStorage) {
    xdLocalStorage.getItem(key).then(function (response) {
    	console.log(response.value);
    });
});

Demo

Here's the demo

Tests

I covered the basic API with tests here

Limitations

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+.