I have a requirement where I have a postgresql database in a web site.
I want to run my web site in offline mode but the problem is that I have many ajax calls in my website which will not work in offline mode.
So I am considering using sqlLite but I don't know how to configure it, how to write JavaScript code, or even know if the users need to install sqlite in their browser or PC. Can anyone help to overcome this requirement?
I have used some local storage like Indexed DB it will work but that is called sqlLite or not I don't know.
please help
You do not need to work with Sqlite for addressing this, only take a look at following link for how to make web pages available for offline viewing.
If you namely want to use some database it is possible to use SQLite.
Look at https://github.com/kripken/sql.js/
Be care of using SQLite requests in main UI thread. Do not forget to implement workers for SQLite.
I'm pretty sure that you do not need SQLite.
Try using HTML5 LocalStorage API.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
The Storage interface of the Web Storage API provides access to the session storage or local storage for a particular domain, allowing you to for example add, modify or delete stored data items.
If you want to manipulate the session storage for a domain, you call Window.sessionStorage method; If you want to manipulate the local storage for a domain, you call Window.localStorage.
https://developer.mozilla.org/en-US/docs/Web/API/Storage
Related
I am building an application using ReactJS. I am trying to find out how to store data and to edit it. I tried to store it on my computer with 'fs, 'browserify-fs' but it didn't work.
Should I use express, or is there any other alternatives ?
If you are using React you are operating in the browser. Your option for storage is in local storage. This is explained here.
Examples of code are:
// setter
localStorage.setItem('myData', data);
// getter
localStorage.getItem('myData');
// remove
localStorage.removeItem('myData');
// remove all
localStorage.clear();
Note this is stored in the browser and can be easily cleared. You are going to realize that you need a back end solution. This is a server you can send requests to which has an API (a place you send requests to) which executes some form of operation (normally CRUD - Create Read Update Delete via a REST endpoint or GRAPHQL) to serve you back the data you are requesting from a database (MySQL, Postgres, MongoDB). This is a whole different discussion.
To store an array in local storage you will need to make it a string via JSON.stringify. An example would be:
localStorage.setItem("array", JSON.stringify(array));
In developer tools in Chrome you can go to Application -> Storage -> Local Storage and see what is saved. Here is an example:
If you want to share the data along multiple clients you should use server-side solution or if you just want to save the data for a client only you could use client-side solution provided by #diesel.
Create your own web-server
You need to create web server and a database to store your data. Database is used to store data. You could use: MySQL, PostgreSQL, SQLite3, MongoDB, ... You also need to create web service to make secure database calls.
To create web server you could use Express.js to write your web server easily.
Headless Content Management Systems (abbr: CMS)
If you don't want to spent time on creating your own web-server you could install a headless CMS to read/write your data using api endpoints provided by CMSs. Here's list of headless CMS softwares: headlesscms.org. I tried strapi which has lots of features you might need.
Here's some strapi features:
Open-source
Model builder
Extensible (plugin support)
Content editor (eg: to edit articles)
and many more
Firebase
If you don't want to spend your time on installing CMS software to your server and maintaining it regularly you could use Database service provided by Google Firebase. It is also feature rich too. Here's some features supported by Firebase.
NoSQL Database (to store your data)
Authentication (to authenticate users)
Storage (to store files)
Functions (to write serverless functions)
Machine Learning
and many more
Is there any way to store persistent data for Chrome Extensions without using a web server?
Is Chrome storage persistent? https://developer.chrome.com/apps/storage
I want to avoid the costs of a server, but I also don't think localStorage is good enough because the user can delete it.
In fact, the only persistent data I need to store is the accounts that have logged into the extension on the device itself, so that info might be stored by Google's servers already?
I don`t think there is an non-server way to store extension data without user being able to modify it.
However there are lot of great services that offer free plans for many platforms eg. Heroku
I am building a reactjs appliacation with a service oriented architecture in which data will accessed through web services. There is also a login feature in it. I am confused about where I store the user session after login i.e. localStorage or cookies. Which one is the best.
There are some pros and crons of both of that. Like,
local storage can be accessed using javascript and also all browser
does not support local storage whereas
cookies have too low web storage to store data as compare to local
storage and also with each server calls cookies will send the data
stored to server, this will affect the site’s performance.
So I just need your help to find the better way to do this.
Sorry for the english if something wrong. Thanks in advance for help.
I am new to angularjs. I want to pass localstorage variable from one angularjs project to another angularjs project. Both projects are on same server.
I am passing localstorage variable from http://site1.in/ as,
window.localStorage.setItem('is_provider', 1);
and I want to use this localstorage variable to http://site2.in/.
I don't know how to get this variable in site2.
Please help.
You can't, localStorage is per domain specific.
Local Storage Privacy
Website A and Website B would have their own local storage. Usually you would have to store certain information in a server database and sync it to the local storage.
I would use the local storage as a cache to get data once and update it at a certain interval depending on when I would want to invalidate the cache. For instance, you could sync with the server when the user A would log out and user B would want to login.
Have a look at the Privacy section in the HTML5 spec for Web Storage.
More information information and resources here: HTML5 Rocks.
Testing
I would suggest the use of a local server setup such as Linux/Mac/Windows, Apache, MySQL, PHP stack (LAMP/MAMP/WAMP) to test on localhost (127.0.0.1).
Most browsers will limit you to 5 MB per domain for every window and tab because of the HTML5 spec recommendation.
I haven't tried this, but you could perhaps have a look at changing the port number of the localhost in Apache's httpd.conf (to do so, find Listen and change the port associated to it) and see if this will do the trick. Basically, you run each test under a different port number to have the whole storage limit for each test.
An alternative would be to create a Chrome extension. You can read more information about this here:
Managing HTML5 Offline Storage
Manifest files
Maybe this link can help: http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/
And NO they cannot be without trickery
I found a way to pass data from one domain to another. You can use cross domain local storage to send data. I have used this and it's very simple. Refer to the site https://github.com/ofirdagan/cross-domain-local-storage
How can Javascript (running from a website on a remote server) access data from a user's local computer?
I have access to all the user's computers and they are all using Chrome.
The data may be stored in a file, a database, I can even run a webserver on their computers if needed, etc.
Is there any way for my users to for example allow my website to access data from JavaScript?
(maybe be there is a Chrome setting but I still want their browser to be secure)
As far as I know, you cannot access the files on the user's machine using javascript. This would be a huge security hole. You have to write a client (not web) application (windows app or whatever technology you are using).
this is not possible just using a browser, because as you said yourself it would`t be secure. You can use some kind of plugin which your users have to allow which then can access the local data on the computer.
It sounds like you are flexible as to where the data is stored in the user's computer. In that case use localStorage or Web SQL Databases. Web SQL Databases are no longer part of the HTML5 spec, but they are supported by Chrome. Using either of these methods will store the data on the users computer - right in the browser in fact.
Edit: In the application that provides the caller id data, have it launch your website with chrome passing in a querystring argument containing the needed caller id data. Then in your page, have it listen to the onstorage event, and update the dropdown when the appropriate localStorage data has changed.
In your caller id app, call:
%ChromeInstallPath%\chrome.exe "http://foo.com/caller?Bill+Gates#425-882-8080"
In your caller handler, use this JavaScript:
window.onload = function() {
localStorage.callerId = location.search;
};
In your page with the drop down list, use this JavaScript:
window.onstorage = function() {
setDropDownFromCallerId(localStorage.callerId);
};
What do you mean by access? does the server-side code need to grab additional info during processing a request?
Is this data that is exclusive to your app (that is, only you create, read, update it.)
If this data is exclusive to your app, then why not store it in HTML 5 Local Storage