What is the duration that browsers retain downloaded assets during a single session?

Is it necessary to preload data from the server in order to have immediate access when needed? The data is stored in a file named "data.json".

Initially, I considered storing data.json in an object and referencing it whenever required.

However, given that there may be a delay before the data is actually needed based on user actions, concerns about memory management arise due to the large size of the object (~5 mb).

My query is regarding whether the browser caches the data.json file internally during the website session when retrieved via ajax.

In other words, if the file is requested via ajax a second time, will the browser fetch it instantly from its internal memory rather than going back to the server?

If this is the case, it might be redundant to save an additional copy of the file in JavaScript. However, there appears to be lack of information or standards available online regarding this topic.

In short, should I store the downloaded file in an object or rely on browsers to handle caching internally?

Answer №1

In this situation, there are various types of "cache" at play. It seems like you're inquiring about how long the browser's JavaScript engine retains an object in memory, and the answer is simple: for as long as there is a reference to it.

On the contrary, the browser's (HTTP) cache has a longer lifespan; individual entries can persist for days, weeks, or even years, depending on factors such as available space and freshness headers on the response.

Based on your scenario, it may be beneficial to prefetch the JSON data into a local cache file and then load that cache file into JavaScript only when necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for relocating Express server (using MERN stack) to a subdirectory and functioning on Heroku

In my MERN stack project, I recently had to reorganize the server-related files into their own subdirectory due to issues with ESLINT, VSCODE, and package.json configurations that were causing errors. However, after making this change, Heroku started thro ...

Click event not functioning correctly in Internet Explorer

When using jQuery, I have the following code: <script type="text/javascript"> $(document).ready(function(){ $('body').on('click', '.add-photo',function() { $("#images").append($('<input/>').attr(&apo ...

Validation issue with Reactive Forms not functioning as expected

My latest project involves a user signup component that I created from scratch import { Component } from '@angular/core'; import {UserManagementService} from '../user-management.service'; import {User} from "../user"; import {FormBuild ...

Can SailsJS be used exclusively for API processes?

Can SailsJS be used solely as an API? After downloading the Sails project, is it possible to exclude the views and focus only on utilizing Sails as an API? ...

Adding an element to a jsonb array in PostgreSQL, but ensuring it is unique

For my PostgreSQL (v10.0) database setup, I followed these steps. CREATE TABLE test (id INT, animals jsonb) INSERT INTO test VALUES (1, '["[monkeys, 10]", "[hamsters, 7]", "[foxes, 3]"]'), (2, '["[monkeys, 10]", "[hamsters, 7]", "[fo ...

Adjust the Bootstrap date-time-picker to accommodate various languages, while ensuring that the selected date and time are displayed in English

As I work on my app, I've implemented localization support for multiple languages. When initializing the datetimepicker in the app, I provide the current language like this: datetimepicker({ locale: languageObj.language, format: 'DD MMM ...

The elegant-admin template's mobile navigation toggle is missing

I recently downloaded an admin theme and added the CSS to my Django static files. However, after doing so, the mobile toggle feature disappeared. I double-checked all the CSS and JS links in the index template, and they are correctly linked to the paths, b ...

Efficiently accomplishing this task with jQuery

Below is a compilation of items along with their corresponding item hashes: 347366834 AceofSpades 460724140 TheJadeRabbit 814876685 TrinityGhoul 1345867570 SweetBusiness 1508896098 TheWardcliffCoil 1852863732 Wavesplitter 2044500762 TheQueenbreake ...

The controller in Angular uses the $scope symbol _

App.controller('todoController', function ($scope) { // create a message to display in our view $scope.todos = [{ name: 'angular', done: false }]; $scope.clearTodo = function () { $scope.todos = _.filter($scope.tod ...

Implementing batch processing and scheduling API requests in node.js using async functions

I am currently working on analyzing a social network graph, specifically focusing on creating a "six degrees of separation" tree based on adjacency lists obtained from an API. The challenge lies in the fact that there is a large number of individuals in t ...

The pause button will still function, even if the scrolling feature is enabled

I've successfully implemented a feature that pauses and plays the video on scroll when it reaches a certain pixel height. However, I'm facing an issue where the code automatically plays the video whenever the scroll position is more than 13500px ...

How can I retrieve the content from an iframe whenever its state is altered using jQuery?

I am currently working on a project where I need to extract the content from a hidden iframe and display it as HTML in a div every time the iframe changes its loading state. The goal is for it to appear as if the page is being redirected and downloading it ...

Slide your finger across the screen to reveal the next image

Seeking a guide or script that can help me showcase images within anchor tags and allow users to swipe left or right to view the next image. Preferably something compatible with JSON, jQuery Mobile, and includes a feature indicating the total number of i ...

Retrieving Array keys from PHP using jQuery

As a beginner in jQuery, I am eager to learn how to retrieve Array keys from a php file using jQuery. Currently, I have jQuery code set up to send input to file.php and execute a query on every keyup event. When file.php echoes the result, it looks somet ...

Transform a series of terms into a JSON file and store it for future reference

I am in need of a list of words that I want to extract from an API request and save in a JSON file. The words are simple, without quotes or commas, arranged as follows: word1 word2 word3 I aim to store them in the JSON file in the following format: [ ...

Ideas for displaying data or a message only once when selecting multiple checkboxes in jquery

code: <script> $(document).ready(function(){ $(".choose").click(function(){ job_type = $(':checked').map(function() { return this.value; }).get().join(',&ap ...

How can we set up a form to submit automatically when the user enters the correct response?

I am currently developing a webpage that includes an image display and a form with a text input field. Is there a possibility to have the form automatically submitted when the user enters the correct answer in the text input field? ...

Navigate a JSON object using JavaScript

As I continue to juggle learning code with my job, I am diving into the world of creating charts using AMcharts. My goal is to generate multiple data sets based on orientation and potentially expand further in the future. In the JSON snippet below, you can ...

The concept of CSS sprites and managing background positions

I have been working on integrating a star-rating widget that requires the use of a sprite file. The sprite file I am using looks like this: https://i.stack.imgur.com/ZSMMj.png This is how my HTML is structured: HTML <span id="star-ratings" class="c ...

Is there a way to transform vanilla JavaScript code into Vue.js code?

// Vanilla JS Code Conversion const app = new Vue({ el: '#app', methods: { // Logged out Events loginHelp: function() { this.$refs.forgotten.style.display = 'flex'; this.$refs.login.style.display = 'none&apo ...