Unexpected behavior in Firefox occurs with PreloadJS when trying to preload elements that are added to the page after the initial load

I'm encountering an issue with the behavior of PreloadJS specifically on Firefox. It's surprising to me that no one else seems to have experienced this problem before as I couldn't find any similar descriptions online. Perhaps I am simply overlooking something... it works perfectly fine in Google Chrome though.

Here is the JavaScript part:

$(document).ready(function () {
  var preloadBG = new createjs.LoadQueue();
   preloadBG.addEventListener("fileload", function(){
     $('#light').css("background-color","green");
     $("#container").append('<div id="image"></div>');
   });
   preloadBG.loadFile('http://i.imgur.com/ifvZ5Ss.jpg');
});

View the example here: http://codepen.io/Deto15/pen/KdpRdx

If you run it on Firefox and do a Ctrl+F5, you'll observe the behavior I mentioned.

Essentially, what I am attempting here is:

  1. Upon document ready, PreloadJS preloads an image (which is not yet utilized on the page).
  2. Once the preloading is complete, the red circle transitions to green.
  3. Immediately after that, a new div is added to the page, using the previously preloaded image as its background-image.

In Chrome, the image appears almost simultaneously with the color change of the circle - which makes sense since it has been preloaded. However, in Firefox, there is a delay between the color change and the appearance of the image, giving the impression that Firefox is loading it again.

Is there a reason for this behavior and is there a solution to resolve it?

Answer №1

Upon comparison in development tools:

It appears that Firefox is not fetching the image from cache, while Chrome successfully does so.

A potential solution could be linked to the size of the image, as elaborated here.

I recommend experimenting with smaller images initially to determine if this addresses the caching issue.

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

The Ajax success callback is failing to update the background-image property after receiving a successful JSON response

I am struggling with setting a background image in wordpress despite receiving a successful ajax response. The image url is being returned successfully in the json response, but I can't seem to set it as a background image. Here is the ajax function ...

"React's ambiguous understanding of 'this' within a function

Can anyone help me understand why the value in the renderInput function is showing as undefined? I've checked the code and everything seems fine. Here is the error: Uncaught TypeError: Cannot read property 'renderError' of undefined This ...

How to retrieve the row index from a table using JavaScript

This question has cropped up numerous times, and despite trying various solutions suggested before, none of them seem to be effective in my case. Within a modal, I have a table where users can make changes that are then used to update the database. The ta ...

Is it possible to connect to a Node server from outside the network if the application is only listening on 'localhost'?

When utilizing the Express framework and we implement app.listen(port), the app will be located at localhost:port/ On a local machine, it is clear how to access this address using a local browser running on the same machine. Even clients within the same n ...

When I shift a JavaScript function from inline code to a separate JS file, I encounter the error message "function is not defined"

I am struggling to get a simple task done: <!DOCTYPE html> <html lang="en"> <head> </head> <body> <script src="js/test.js" type="text/js"></script> <button onclick="test()" type="submit">Test</button> ...

Is there a way to grab the inner content of an e-mail link by right-clicking on it?

I am currently developing a Chrome Extension that functions similarly to the "Search on Google" feature when you right-click on selected text. However, I am facing an issue with making it work when right-clicking on a mailto: email link. How can I extract ...

Exploring front-end AJAX functionality within a WordPress plugin

As a newcomer to WordPress development, I have been working on writing an AJAX request within a WordPress plugin. To test this functionality, I initially sent the request to an external non-WP server where it worked without any issues. Following the guidel ...

Retrieve the most recent score of authorized players using the Google Game API and Node.js

How can I display the last score of a specific game using the Google Play Game API? For example, I am looking to retrieve the latest scores of authenticated users playing "Rush Fight" with NodeJS. Any suggestions on how to achieve this? ...

The development server for Vue JS is not functioning properly in the Atom editor

After beginning my website project in Visual Studio Code and having it run smoothly for days, I decided to switch over to Atom. However, upon starting the dev server in Atom, every Vue component started showing the following error: Console output (pastebi ...

Code for object creation, inheritance, and initialization

In the code snippet below, a class is defined for managing input events such as mouse, touch, and pointer: // base.js export default () => { return { el: undefined, event: undefined, handler(ev) { console.log('default handler&a ...

What causes the timer to pause, and what steps can be taken to avoid it? (Using Javascript with Iframe)

On my website, I have a page where clients must view an advertisement for 20 seconds. The website is displayed in an iframe with a countdown timer above it. I've set it up so that the timer stops when the window loses focus to ensure the client is ac ...

Utilizing React with Material UI: Customizing MuiTheme within a component using withStyles

Currently utilizing Material UI in conjunction with React. I am attempting to customize the style of the TextField component, which has been configured using a global theme. The global theme has been set up for all TextField components within the applicati ...

Why does my dialog box only open the first time and not the second time?

I have created my own custom dialog box using jQuery and it seems to be working fine initially. However, after closing it once, when I try to open it again nothing appears. Can anyone help me identify what's causing this issue? Below is the source co ...

When utilizing Angular 2, this message is triggered when a function is invoked from the Observable

One of my services is set up like this: @Injectable() export class DataService { constructor(protected url: string) { } private handleError(error: Response) { console.log(this.url); return Observable.throw(new AppError(error)); ...

Rendering components asynchronously in ReactJS

After completing my ajax request, I need to render my component. Here is a snippet of the code: var CategoriesSetup = React.createClass({ render: function(){ var rows = []; $.get('http://foobar.io/api/v1/listings/categories/&apo ...

What is the process for importing the util module in Node.js?

I attempted to use the isDeepStrictEqual() method for object comparison but encountered this error: util.isDeepStrictEqual() is not a function After checking the official documentation, I found out that this method was introduced in Node.js v9.0.0 w ...

Is it possible to employ a jQuery handler as the selector for the .on() method?

Can a jQuery handler $(...) be used as the selector for .on()? The code snippet below illustrates this: how can I change the circle's color to blue without having a plain text representation of my selector, but still using a handler? // This works. ...

Javascript callback function cannot access variables from its parent function

As a Javascript newbie, I am currently diving into callbacks for my project. The goal is to retrieve address input from multiple text boxes on the HTML side and then execute core functionalities upon button click. There are N text boxes, each containing an ...

Error: PDFJS is not recognized in an Asp.net environment

Trying to showcase a PDF using the canvas and PDF.JS Stable v.2.2.228, but encountering an error in the console that says: ReferenceError: PDFJS is not defined. Information points towards the removal of the global PDFJS object; however, struggling to find ...

Incorporate a Font Awesome button in front of the content of each list group item in Pug/Jade

I'm struggling to insert a Font Awesome icon before the list-group-item content within a Pug loop, but I can't seem to make it work. Adding the icon at the end of the list-group-item content is straightforward. How do I position it in front (I h ...