How to store and access JSON data for a site?

I am creating an HTML / jQuery site where almost all of the content comes from deleted JSON data. I'm having trouble with a good way to store and access data in the future (in terms of reach).

I have currently written a jQuery plugin that receives JSONP data when a site loads. But I have other jQuery functions and plugins that need to access this data.

Where should this data be stored so other functions and plugins can access it?

Should it be a global variable?

If that matters, this site will only work on the iPad, and the server server will work on Rails.

+4
source share
4 answers

I would advise you to explore the persistent HTML5 repository that is supported by Safari and Mobile Safari in the form of SQL Lite DB. If you decide not to follow this route, I would choose $ (). Data () over a global variable in JavaScript.

+4
source

If there is a manageable amount of JSON data, you can access it through global variables. Only one or two global objects with nested properties are preferred.

Web page development is not like library development. I think a few globals are acceptable.

+1
source

To save data between requests, you can use the HTML5 Storage API . Otherwise, just pass a variable (link) containing the data.

+1
source

Dojo has it.

If you have no restriction on the use of jquery, you might be able to explore it.

http://ajaxian.com/archives/dojostorage-offline-access-and-permanent-client-side-storage

Alternatively, you can also just store it in an array that other plugins / functions can access.

0
source

Source: https://habr.com/ru/post/1305884/


All Articles