4

I am trying to write a JavaScript script that is "overlayed" on top of a Facebook page. It uses DOMContentLoaded to detect when content is loaded, then adds some extra stuff in. However, because Facebook doesn't actually "reload" the page when going to a new page (it just uses AJAX), the DOMContentLoaded handler doesn't run again, even though there is new stuff to look through.

Anyway, to detect the change, I thought about using onhashchange since Facebook used to change the page's hash, but in Firefox 4 (I need to support Firefox 3 and later with this, but no other browsers), Facebook doesn't change the hash anymore and in pre-Firefox 3.6 there is no onhashchange.

I thought about using DOMNodeInserted, but would that really slow down the page? (I really can't have any slowdowns in this script.)

000
  • 26,951
  • 10
  • 71
  • 101
jakey
  • 41
  • 2
  • Has anyone else tried to implement DOMNodeInserted? Was speed/responsiveness a problem? (I do have a pretty big callback function) – jakey Dec 26 '10 at 22:44

2 Answers2

1

For lightweight pages it generally doesn't have noticable effect. However, on bulky pages (I tried this on gmail) it makes that really really slow that I cannot even compose a message smoothly. And that event was added to a very simple span element which just had a single link in that. The events like DOMNodeInserted and DOMSubTreeModified are real show stoppers.

UPDATE: For all those trying to find an answer to this, note that these methods DOMNodeInserted (or DOMSubtreeModified) really had performance problems, so according to new ECMA specs it is a much faster listener : MutationObserver for doing the same thing (and more).

https://hacks.mozilla.org/2012/05/dom-mutationobserver-reacting-to-dom-changes-without-killing-browser-performance/

Piyush Soni
  • 1,356
  • 3
  • 17
  • 40
1

you might want to monitor the windows.history object, see the following answer, on how facebook uses it to update pages: "Redirect" page without refresh (Facebook photos style)

Community
  • 1
  • 1
user280109
  • 1,476
  • 3
  • 16
  • 27