Managing images in JavaScript while conserving memory

Welcome

I am embarking on a project to construct a webpage using HTML, CSS, JavaScript (jQuery), and nearly 1000 images. The length of the HTML page is substantial, around 5000px.

My vision involves creating a captivating visual experience for users as they scroll through the page. I want the images to animate like a flipbook in the background, synchronizing with the user's scrolling progress. For instance, if the total image count is 1000 and the user has scrolled 32% down the page, they should be viewing the 320th image. Upon reaching the end of the page, they will see the final 1000th image.

How can I tackle this efficiently? Each image file size averages about 150kb, and it is crucial for me to preserve their quality without further compression.

Exploration So Far

  1. Maintaining all images in memory constantly

    New images are loaded as the user scrolls, while previous ones are hidden with display: none;. Although functional, this method becomes progressively sluggish with extended scrolling.

  2. Limited image retention in memory

    This method involves loading the current image along with 20 preceding and following images. Images beyond this range are "removed from memory". Despite efforts, performance issues persist, possibly due to inadequate memory management practices.

Inquiry 1

What techniques or strategies would you recommend for optimizing this project?

Although option 2 seems promising, I am open to alternative suggestions that could enhance efficiency.

Inquiry 2

How can I effectively remove images not just from the DOM but also from memory?

To ensure the success of this project, proper handling of image removal seems necessary.

Current Strategy

Here's an overview of my current approach:

var imageNum = -The current image number to be displayed-;
var flip = -the container element housing all images-;

flip.children().each(function(i, e) { 
    var jE = $(e);
    var childInd = parseInt(jE.data('page-number'));

    if (childInd < imageNum - 20 || childInd > imageNum + 20) {
        jE.removeAttr('src');
        jE.remove();
        jE = null;
        e = null;
    }
});

The section above raises concerns regarding proper memory release:

jE.removeAttr('src');
jE.remove();
jE[0] = null;
e = null;

These lines were composed after consulting various sources. Since no event handlers are attached to the images, this aspect is likely not problematic.

How can I ensure effective garbage collection to free up memory occupied by these images? Is my current procedure adequate to facilitate memory liberation?

Answer №1

By utilizing image sprites, you have the ability to create one composite image containing multiple individual images, allowing you to retrieve each image using specified coordinates.

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

Tips for arranging images in a horizontal layout using FlatList in React Native

Is there a way to display feed images horizontally instead of vertically in FlatList? I've tried wrapping the images in a view with flex-direction set to row, as well as adding horizontal={true} to the FlatList, but nothing seems to work. Any suggesti ...

Are you experiencing issues with your Ajax request?

I've been struggling to retrieve json data from an API. Despite my efforts, the GET request seems to be executing successfully and returning the correct data when I check the Net tab in Firebug. Can anyone offer advice on what could be going wrong or ...

React Ant Design: Toggle Visibility of Columns

Seeking a method to toggle the visibility of columns for the Table Component in Ant Design. The goal is to include a checkbox next to each column name. When unchecked, the column should be hidden. In my previous experience with react-table, accomplishing ...

Content is missing from the response of the AngularJS $http request

Attempting to retrieve content from a website using Angular's $http service. The request seems to be successful as console.log(response.data) displays most of the content but is missing some parts. Check out my code below: $http = angular.element(doc ...

How can I utilize Bootstrap to properly space items within a layout?

I'm having some difficulty creating spaces between the controls while using ml-auto. My goal is to have each control separated with spaces in between, specifically the "Core Status label" should be far apart from each other and aligned on a horizontal ...

Having trouble extracting the Top-Level Domain from a URL

I'm struggling to find a reliable way to extract the Top-Level Domain from a URL. The challenge I'm facing is that the URLs entered by users can vary greatly - they might enter www.google.com, m.google.com, m.google.uk, google.uk, or www.m.google ...

Survey with results routing based on rating

I am looking to incorporate a basic survey on my website featuring a few multiple choice questions. Each question will be assigned a score, and upon completing the survey, users will be redirected to a personalized page based on their overall score. Doe ...

Using jQuery to first conceal the container before displaying the element within it

I need assistance with hiding a container element that has the class page_wrapper. After hiding it, I want to ensure that only one element within that container is displayed; this element has the id infinite_math_container. This is what I have tried so fa ...

SCRIPT5007: The property 'href' cannot be assigned a value as the object is either null or undefined

This script is functioning properly in browsers like Chrome and Firefox, however it is encountering issues when used with Internet Explorer. An error message is displayed in the IE console: SCRIPT5007: Unable to set value of the property 'href': ...

Intermittent occurrence of (404) Not Found error in the SpreadsheetsService.Query function

Using the Spreadsheet API, I frequently update various sheets. Occasionally, and without any pattern, the SpreadsheetsService.Query function returns a (404) Not Found error. This issue does not seem to be related to internet connectivity or server downti ...

When you assign the page results from the scrape-it npm to a variable, it will return a Promise with the status of "pending."

I recently downloaded scrape-it from NPM as a dependency and I'm trying to store the results in a variable instead of using a callback function. When I run the code snippet provided in the scrape-it documentation: var myVar = scrapeIt("http://ionicab ...

I'm looking for guidance on how to properly implement onChange in this particular script. Any help with the correct syntax

Can someone help me with the correct syntax for writing onChange in this script? I want to integrate these phpcode into my script. Here is the Javascript code: ih+='<div class="form-group drop_bottom" id="select_one_'+extra_num+'">< ...

What are the steps to fix a timeout error with React.js and socket.io acknowledgements?

My setup includes a Node.js server and a React.js client application. Data is exchanged between them using socket.io, but I'm running into an issue with implementing acknowledgment. Whenever I try to implement acknowledgment, I receive a timeout error ...

Uploading files in javascript and PHP

I am currently utilizing an audio recorder provided by this source , However, instead of storing the file locally, I am interested in uploading it back to the server. My attempt involved adjusting the Recorder.setupDownload function within the recording. ...

The URL provided by window.location is not accurate

I'm facing an issue with the code window.history.pushState("", "title", myCtxURLVersion); which is supposed to change the current URL of the page. However, when I implement this code, the URL displayed is incorrect. For example, even though the brows ...

The module "angular2-multiselect-dropdown" is experiencing a metadata version mismatch error

Recently, I updated the node module angular2-multiselect-dropdown from version v3.2.1 to v4.0.0. However, when running the angular build command, I encountered an "ERROR in Metadata version mismatch for module". Just to provide some context, I am using yar ...

The position of the carousel items changes unpredictably

My jQuery carousel consists of 6 individual items scrolling horizontally. Although the scroll function is working correctly, I have noticed that 2 of the items are randomly changing their vertical position by approximately 15 pixels. Upon reviewing the HT ...

Incorporating a pre-existing component into a Vue.JS template through an onclick event: How can this

I'm trying to enhance my template by implementing a feature that allows me to add a component simply by clicking on a button. Let me give you a glimpse of what I have in mind: The component named Draggable.vue is the one I intend to incorporate upon c ...

Unable to access the data once CORS is disabled

After enabling cors, I successfully loaded the data. However, when I disabled it, I encountered issues retrieving the data. Is there a way to bypass this without turning on cors? An error message I received is: createHttpLink.js:96 Refused to connect to & ...

Is there a way to delay the start of an ajax function until a few moments after the user

Good evening, I am interested in implementing a new feature using Ajax. Specifically, I would like to introduce a delay of 2 seconds after the user finishes typing before triggering the search function, as opposed to using "onkeyup". Note: This modificati ...