Stopping a page element from loading

2,115 views
Skip to first unread message

AsymF

unread,
Feb 25, 2008, 2:42:24 PM2/25/08
to greasemonkey-users
I have a site I go to frequently that has a massive JavaScript menu
that loads up in some DIV content. It seriously slows up the browser
waiting on it to load. If I wanted to prevent a DIV from loading at
all, how would I do that? Just generically for any site. I actually
have several that I want to stop extraneous content from loading on so
that it doesn't slow up the browser.

Anthony Lieuallen

unread,
Feb 25, 2008, 2:53:36 PM2/25/08
to greasemon...@googlegroups.com
On 2/25/2008 2:42 PM, AsymF wrote:
> ... If I wanted to prevent a DIV from loading ...

That statement doesn't make sense. A <div> is a piece of an HTML page,
and you cannot pick which bytes of a single document to load, and which not.

> ... Just generically for any site. I actually


> have several that I want to stop extraneous content from loading on so
> that it doesn't slow up the browser.

You also mentioned javascript. If you actually want to block specific
_resources_ from loading, rather than a piece of one, than you want
AdBlock, or one of its many derivatives. A separate extension.

RodMcguire

unread,
Feb 25, 2008, 2:56:31 PM2/25/08
to greasemonkey-users
In general you can't because GreaseMonkey runs at DOMContentLoaded
time (after the HTML of a page has loaded but maybe before all things
like images have loaded).

So, if the script is in-line in the web page you can't do anything
about it. However

1) if a script on the page is loaded externally, then you can use an
extension like Ad Block Plus to keep the page from loading.

2) if the script is not just inlined and run (say the menu creation is
triggered by a load event) then you might be able to go in and
undefine or redefine some of the page's Javascript functions to
prevent things from happening.

Such an approach is not general and involves understanding how a
particular web page works so you can defeat part of it but keep other
parts of it working.

http://wiki.greasespot.net/Main_Page
http://wiki.greasespot.net/DOMContentLoaded

esquifit

unread,
Feb 26, 2008, 7:33:00 PM2/26/08
to greasemon...@googlegroups.com
On Mon, Feb 25, 2008 at 8:56 PM, RodMcguire <mcg...@telerama.com> wrote:

> So, if the script is in-line in the web page you can't do anything
> about it.

Actually you can, at least in a number of situations:
1) The simplest approach is to disable javascript either globaly in
Firefox or specifically in this site by means of the NoScript[1]
extension.
2) A more sophisticated way is via CAPS [2][3][4]. In this case you
can prevent function execution (among other things) on a per-function
and per-site basis.
3) An in-line script which is not being called through a function call
can in general still be disabled via CAPS, but it normally requires
more work.

An in-line script with does not fall in any of these categories is
unlikely to contain more than two or three lines of code and should
not lead to any performance problem.

[1] https://addons.mozilla.org/en-US/firefox/addon/722
[2] http://www.mozilla.org/projects/security/components/ConfigPolicy.html
[3] http://kb.mozillazine.org/Security_Policies
[4] http://kb.mozillazine.org/Allowing_only_certain_sites_to_use_JavaScript

Reply all
Reply to author
Forward
0 new messages