Bug Tracker

Modify

Ticket #5443 (closed bug: duplicate)

Opened 4 years ago

Last modified 2 years ago

[with solution and fix proposal] sporadic error "document.body is null" and continuous page reloads

Reported by: beat Owned by:
Priority: major Milestone: 1.4
Component: event Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

The effect of this error can be disastrous to web servers, as it can reload the page continuously, and fix seems simple at first glance: don't trust the domready event from browser, but check that document.body is not null before accepting that event as valid:

Sporadically I had in firefox 3.5.4 the error "document.body is null"

This was exactly reported in IE too here:  http://groups.google.com/group/jquery-en/browse_thread/thread/70e8a050f60f8b08

(that thread being closed, i am opening a new one here)

Interestingly turning cache off with webdeveloper plugin, the error came systematically, and *worse*, did systematically reload the page automatically, cycling the like F5 button pressed permanently, putting load on server. But that also allowed to use firebug to debug.

  • When not having any javascript inline code in head, the error went

away. So this worked fine (no page reloads):

<script type="text/javascript" src="http://www.example.com/
jquery-1.3.1/jquery-1.3.1.js"></script><script type="text/
javascript"><!--
jQuery.noConflict();
--></script>
  • But with just having this it was already permanently reloading the

page with cache off and also throwing error "document.body is null" :

	<script type="text/javascript" src="http://www.example.com/
jquery-1.3.1/jquery-1.3.1.js"></script><script type="text/
javascript"><!--
jQuery.noConflict();
--></script>
	<script type="text/javascript"><!--
jQuery(document).ready(function($){
/*
*/
});
--></script>

No other javascript in the page, only CSS files and valid transitional HTML !

Finally, I saw that in the site template, some CSS files where loaded after that javascript code, and being jQuery 1.3, it's better to load them before....

So i have put all CSS files <link> before the javascript code above, and the error disappeared completely.

As this is a recommendation for jQuery 1.3, well, you could classify this as a ... template-designer-error, but still:

IMPORTANT CONCLUSION:

*However* : if a site template (e.g. in joomla, where the template used by the site is not under the control of the extension developer using jQuery) puts some CSS files after the Javascript headers, then the issue that *it triggers permanent fast page reloads* is a big issue for webserver sanity, and imho something should be done in jQuery to check at least check for the condition "document.body === null" before deciding that the document is ready.

So that should be fixed in jQuery imho, not just trusting the dom ready event, which seems to be fired too to early on CSS file loads, but to check that there is really a document.body there before trusting the event and starting touching the body even before it exists.

Best Regards, Beat

Change History

comment:1 Changed 4 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed
  • Component changed from core to event

comment:2 Changed 4 years ago by dmethvin

This appeared to be the same as #4320 which didn't have a test case, so I closed it as well.

comment:3 Changed 4 years ago by john

  • Status changed from closed to reopened
  • Resolution fixed deleted

Actually, I fixed this incorrectly - backing this change out. It's a generic IE/Firefox issue and after reading some of the other tickets it seems as if.

This is a duplicate of #4406 and #4320.

comment:4 Changed 4 years ago by john

  • Status changed from reopened to closed
  • Resolution set to duplicate

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.