JS Cross domain offline local storage - javascript

I have a web page that usually suppose to work offline.(without internet connection).
Once a while it's need to connect to the web and grab some data to be used offline.
I'm searching for a way to store the data locally while it connected and still have an access to the data offline.
I checked local storage and the FileSystem-API but both are follows the Same Origin Policy.
Any suggestion will be appreciate

When I was creating offline application to sync with online version I had some JSON file with required information instead of LocalStorage.
Work flow:
User requests new files to be generated (a.k.a. sync with server) using some online interface.
Generate JSON file with needed data and save it along offline files.
User downloads new files and replaces it with old ones.
Offline JS reads JSON file and gets all information.
We were using some JAVA installer (launch4j to generate .jar files and IzPack to make installer)

Related

How to fetch data as .csv file from client with node.js application

i have written a game in javascript with the p5.js library. Now i want to host the game on a server to conduct a survey on a service like amazon turk. Ideally the clients recieve a URL to the game and play it while in-game actions are tracked and stored in node.js or on the server and exported as a .csv file once they are done playing. After they finish the game the csv. file should be sent automatically to a location that i can then access. I have zero experience in server hosting or similar topics.
So a couple questions arise:
Is a hosting service like Heroku suitable for hosting the game?
Do i need to use node.js to make this happen?
Which of those two would extract the data and store it to a csv? And where is the file stored?
How do i get or access the csv. after?
Any alternative takes to solve the problem?
Thanks alot in advance!
github repository: https://github.com/luuuucaaa/schaeffers-charade
game on github pages: https://luuuucaaa.github.io/schaeffers-charade/
If I were you, I would do it like below:
Host
Since your project is basically a html & JavaScript static contents,
AWS S3's static hosting would be sufficient (Also, the current git hub pages is another option if you just want to host it).
Hosting on node.js environment is also available using webpack serving, but it requires additional works. (but if you require other npm packages to generate .csv file, you need webpack anyway to bundle js file and attach it to html)
Data Storing
Two ways are considerable,
the first is to store it on the filesystem. Generate .csv via JS script within your app, and save it where the app is hosted (if you go with s3, you can access it afterwards, but I'm not sure if it can write objects by script)
The second is to post the data to another API endpoint. (for example building an API Gateway on AWS that triggers Lambda, which stores it on S3)
It's merely an example and I don't know exactly what you want to achieve, but take it into considerations. Good luck. Cool game BTW.

I'm looking to connect a Google VM to a website

I need reflection, vision and documentation on my problem.
I wrote a python script to calculate something from an API and export the result in a CSV file. Then, I use a JavaScript script to display the data from this CSV file on a building website.
I need to have the latest data available for my website, so I opened a VM instance in Google Cloud Platform (Google Compute Engine) and set a Crontab job to run automatically my python script. The calculation is now executed every day and the result is exported to the CSV file, but stored in this VM instance.
Here is my goal: How can I get my CSV file on my website? The CSV is always on the virtual machine and I do not know how to communicate with my JavaScript script to the VM. Do I have to communicate directly with the VM? Do I have to go through another step before (server, API, etc.)?
I cannot find a specific solution for my problem on the internet.
Thanks in advance.
How can I get my CSV file on my website?
By making your python script output the CSV into your website's root folder.
Example, if you're running apache, chances are your root folder is somewhere in /var/www/html/...
If the script is generated from another machine (not the one with your website), then I would host it and make the server hosting your website fetch it via cronjob.
Basically:
If your CSV is generated from the same machine as the website that will use it - simply output it to the website's folder
If your CSV is generated from another machine, make it publicly accessible and have your website's machine cronjob fetch that CSV a few minute after it's generated.
I would suggest you a different approach than using a VM for calculating and storing your CSV.
The idea would be using a Python Cloud Function instead, that will be run by Cloud Scheduler and Pub/Sub.
This function will generate your CSV file, that will be stored on Cloud Storage. Here you can find an example of how to upload an object to Cloud Storage using Python.
Then, you need to give your website the ability to access that CSV file in Cloud Storage when required. As indicated by #guillaumeblaquiere, the exact way will be dependent on where your website is hosted: especially, it will constraint the auth mechanisms that you need to use to download your data. The documentation in GCP provides several examples about this matter.
The documentation of Google Cloud provides an example of the proposed architecture.
I came across an article that, in a certain way, describes the setup I suggested as well.
Please, consider review the costs of the different mentioned products.

Write a file on local disk from web app (ReactJS)

I'm developing a web app using ReactJS and trying to create a txt file with a number in it on the local storage, c:\temp for example.
Is it possible to do it without keep asking the user for his approval (dialog)?
Thanks
localStorage is a browser API and not an arbitrary file on the user's disk. If you are going to use it, then there is a handy React hook for it.
You can't write to arbitrary files on the user's disk, although you can generate a download from in-memory data. This may be saved to the user's download folder or may prompt a SaveAs dialog (you can't control which).
If you want to store data on the server then you can make HTTP requests to it (i.e. use Ajax) and write a web service to process those requests.

Not finding a way to store the files for offline download in the offline web application

I'm working on a web application that should work offline.
I'm following "offline first" approach to develop this web application in angular js using service worker specifically "upup" api.
I'm able to cache the html, css, js files and till now it is going good. Now I need to provide a functionality on the web application so that a user should be able to download a file when he is using app offline .
I have study a lots of blogs and also studied "offline cookbook" but not getting any idea of how to implement the offline file download functionality should I store the files in the cache and then user download them when they offline or any other approach will be good?
I have also thought about to store the files in the local db like pouch db but I don't think it would be a better approach.
You have the two options you already listed: storing the file into one of the existing offline storage vaults in the browser or caching it proactively with the Service Worker before the user goes offline.
I would add it to the cache after installing the Service Worker and then return it from the cache when a request comes from the user.
Out of curiosity, what are you making available for offline download? Some PDF?

Can I save a record in a Windows Gadget in a file or other storage (database, etc.)?

I'm planning to create a simple gadget to create a TO DO list application. This is just for practice and to explore Windows Gadget. How can I store the values in the database? As much as possible, I don't want to set up a local http handler file to be a means to store value to file or database.
Note: I tag this with html and javascript since I'm aware it uses such.
Once installed, gadgets run with all the permissions of the logged in user. So you should be able to access the local file system and instantiate COM objects such as ADO to connect to a database.
The chap here wrote a gadget settings persistence manager to allow gadgets to save their settings between being uninstalled and re-installed in the sidebar. He uses the Scripting.FileSystemObject to write out settings to a file:
http://channel9.msdn.com/playground/Sandbox/231595/
This is also worthwhile reading to understand gadget security:
http://msdn.microsoft.com/en-us/library/aa965881(VS.85).aspx

Categories