Skip to main content

Bug Tracker

Side navigation

#5876 closed bug (worksforme)

Opened January 20, 2010 04:24PM UTC

Closed April 17, 2011 06:45PM UTC

Last modified March 14, 2012 12:51AM UTC

domManip caching doesn't evaluate scripts

Reported by: molily Owned by:
Priority: high Milestone:
Component: manipulation Version: 1.4.4
Keywords: dommanip cache Cc:
Blocked by: Blocking:

buildFragment() uses jQuery.clean() to extract the JS code of <script> elements. If it uses the cached DOM Fragment, clean() isn't called. In this case, the 'scripts' array remains empty so that evalScript() isn't called any longer.

Test case:

<p><a href="" id="start">call html()</a></p>

<div id="output"></div>


$(function ($) {

$('#start').click(function (e) {

$('#output').html("<script> alert('should be executed'); <\\/script>");





This works as expected for the first and second click, but the third time the cache kicks in and the embedded script isn't executed.

This used to work in jQuery 1.3. I've encountered this bug in an Ajax environment using .load(). If the Ajax response is the same three times in a row, the embedded scripts weren't executed.

Attachments (0)
Change History (8)

Changed June 14, 2010 12:24AM UTC by dmethvin comment:1

component: unfiledmanipulation

Changed November 19, 2010 09:17PM UTC by snover comment:2

#5818 is a duplicate of this ticket.

Changed November 21, 2010 04:14AM UTC by snover comment:3

blocking: → 6779

(In #6779) Beyond just not testing for strings with no HTML, I suggested to only cache strings where the first character is a <.

Changed November 21, 2010 04:15AM UTC by snover comment:4

priority: majorhigh
status: newopen

Changed November 21, 2010 04:16AM UTC by snover comment:5

keywords: → dommanip cache

Changed December 13, 2010 07:46PM UTC by jitter comment:6

test case I can't reproduce this with 1.4.4 . snover could you reproduce this 3 weeks ago?

Changed December 13, 2010 10:18PM UTC by molily comment:7

Apparently this was fixed in 1.4.2 because this version introduced more checks if a string is cacheable as a DOM fragment. Since 1.4.2, strings that match

rnocache = /<script|<object|<embed|<option|<style/i

are not cached.

This means the script execution problem I had reported does not occur an longer because HTML strings with script elements aren't cached into DOM fragments any more.

Changed April 17, 2011 06:45PM UTC by john comment:8

resolution: → worksforme
status: openclosed