Do browsers cache JSON - json

I want serve a JSON from a storage bucket. The JSON data will be updated periodically, but the URL will remain the same (I don't want to have to redeploy my site with an updated URL every time the JSON is updated). But I know that if this was CSS I would have problems with the browser caching the file and not fetching the updated data. Do browsers cache JSON like they do CSS?

Yes. Caching related headers and (how they are handled) work for all HTTP resources. The file type isn't relevant.

Related

View Raw JSON File in Browser

I'm writing an iOS app which will eventually retrieve data in JSON from a web service. However, before I get the web service running, I just want to test the app's ability to retrieve the JSON, so I thought I could simply upload a dummy JSON file (.json) to the root of a website I have hosted, point my browser to that file's URL and view (or at least download) the JSON.
Unfortunately, when I try to navigate to the JSON file's URL in my browser, I get the message
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
If I use the same URL in Postman I get a different response:
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
I realise I'm doing something stupid here and probably fundamentally misunderstanding something, but after quite a lot of Googling I don't know what! Everybody else with similar issues seems to reporting that they're prompted to download the JSON file rather than just seeing the data displayed in their browser, but I'm not even getting that. It'd be fine if I was! For what it's worth, I've verified the JSON itself in JSONLint.

Open binary file from HTML5 offline web application

I'm able to use HTML5 standard File API and IndexedDB to store large binary files in the browser.
However, when offline, I need to be able to open these files. Using data URLs works great for small files, but none of the browsers support 10Mb file opening through data URL. Is there any other solution, except for non-standard window.webkitRequestFileSystem?
I've actually found an answer here: https://developer.mozilla.org/en/docs/Web/API/Blob.
It is possible to save result of FileReader.readAsArrayBuffer in IndexedDB. When offline, it is possible to create a blob from this typed array and then create data URL to be passed to window.open function. Works with large files!

Deleting data loaded in cache memory during a browsing session

I have a Grails application running with a very heavy back-end data.Every selection made in the view of the application loads a new JSON file.I am new to developing web applications and I assume that this JSON file which is getting loaded is being loaded into the browser's cache memory(It's just a guess and I could be wrong too.Do correct me in that case).
Why I came to this conclusion is because, after playing around with the application for some time and making different selections in the view, I observed that the browser crashes(In my case, it stops responding) after the cumulative size of the JSON files loaded into the cache memory(assuming it to be cache memory) exceeds 200MB.
If the location where the files are being loaded is actually the cache memory(or be it any other storage location),I would like to delete the files loaded previously once a new selection is made.
If this solution is not practical enough then, feel free to suggest any method that will solve my problem.
Any help or suggestion will be appreciated.
You can use the browser's sessionStorage (only accessible within a session inside a tab) or localStorage (accessible across multiple sessions across multiple tabs) using JavaScript.
These can store string data in the form of key, value pairs. So you can fetch the JSON data from a file and convert it into a string using JSON.stringify() and get the data back from the browser's storage from string to JSON using JSON.parse().
Assuming you're using sessionStorage, you can check how many JSON strings you have stored using sessionStorage.length. You can set a limit in your code such that if your limit is reached, you can delete the oldest one using sessionStorage.removeItem(key).

Temporary file handle storage in HTML5

Is it possible to obtain file handles in HTML5 and store it as a blob in webDB for upload later?
(Upload selected images when the 3G network is available again, without re-selecting the files.)
The HTML5 will be loaded from the local client device and
action="http://.../insert.jsp"
be used to upload the files to the server.
Any help or ideas will be very useful.
C-:
Any File object can be converted to an URL.
It is simple to do by using object URLs as described by:
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
(I still have to confirm that the URLs remain valid across sessions.)
And it does not remain valid across sessions in Chrome!

Cache manifest and query strings

I am investigating using a cache manifest. If I have a manifest such as:
CACHE MANIFEST
stylesheets/style.css
And in the page I have a CSS element referencing stylesheets/style.css?v=123.
Will the style.css file be retrieved from the cache or remotely?
The URL in the cache manifest and the URL you're calling must match (INCLUDING the query).
In your example:
CACHE MANIFEST stylesheets/style.css
in HTML: stylesheets/style.css?v=123
The browser will ALWAYS try to fetch the CSS file from the server, since only the query-less CSS file is cached locally. Use of stylesheets/style.css in cache is sufficient.
Just an additional note: if you have HTML pages that expects data in query strings, you could store the same data in localStorage and after redirection can get access the same data in the other page from localStorage.
That is how I solved passing data between pages where we cannot use the query string option with offline cache manifest files.
When you don't have any network connection and want to access that page, it will fetch locally.