animate() in Chrome triggers hundreds of HTTP requests
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 59.8k
- Forks
- 20.4k
- Avg merge
- 17h 32m
- Merged PRs (30d)
- 4
Description
Description
Using .animate() on an element with a background image causes Chrome to re-request the background image 60 times per second, but only if:
- Chrome is in Incognito mode.
- You refresh the page after the initial pageload.
- The CSS that sets the background image is in an external CSS file.
The avalanche of requests does not happen on the initial pageload -- only if you reload the page -- and the requests are always served from the in-memory cache of the image, so it's not actually placing load on the Web server, but the behavior seems... bad.
I've only been able to check this behavior in Chrome 95.0.4638.69 on Mac OS 11.6. The example uses jQuery 3.6.0, but I originally noticed it in a project that uses jQuery 2.2.4. Besides jQuery itself, the only JavaScript being run is
jQuery( function ( $ ) {
$('#animate-me').animate({
'width' : '+=100',
}, 5000, 'linear' );
} );
Link to test case
There is an example here: https://www.chrisfinke.com/files/jquery-animate-bug/
To reproduce:
- Open a Chrome Incognito window.
- Open the Developer Tools and select the Network tab.
- Load the URL https://www.chrisfinke.com/files/jquery-animate-bug/ Note that the 5-second animation completes, and there are a total of four HTTP requests -- the HTML, the stylesheet, jQuery, and the background image (plus the favicon, potentially).
- Reload the page by clicking the reload button. Note that this time, there are 300+ requests -- the same four as the original pageload, but an additional 300 requests for the background image.
This behavior persists even if the animation does not visibly affect the element on the page. For example, if instead of changing the width, it increases the font size (when there is no text in the element).
There are a couple of workarounds for anyone who is experiencing this bug in their own code:
- Set the background image via an inline
styleattribute. - Set the background image via a
<style>block in the HTML.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked test case and the provided jQuery animate() call, reproducing the reload behavior in Chrome Incognito with the Network panel open. Compare the external stylesheet setup with the inline style and HTML style-block workarounds; done means determining whether jQuery can prevent the repeated requests or documenting that the behavior is browser-specific.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100