apsillers
apsillers

Reputation: 115950

Can beforeload cancel HTTP requests?

I've read over the beforeload documentation from Apple, but I'm still a bit uncertain about how beforeload cancels a load, from a network perspective. Apple's documentation says:

Safari 5.0 and later (and other WebKit-based browsers) generates a "beforeload" event before loading each subresource belonging to a webpage.

There's nothing in the sparse documentation here that suggests to me that a beforeload block must prevent a HTTP fetch of the resource. What does the operation of "loading" a Web resource entail (e.g., is there a formal definition of loading in some W3C spec)? In Webkit's current implementation, does canceling a load with beforeload stop the browser from sending a HTTP request, or does it merely stop the resource from being rendered and firing a load event?

I'm primarily instead in these question to assess beforeload's usefulness to block tracking images. I know there are other ways to do this (e.g., Chrome's webRequest API), but I want to know if beforeonload is also suitable.

Upvotes: 3

Views: 640

Answers (1)

Pum Walters
Pum Walters

Reputation: 339

The beforeload strictly speaking doesn't prevent anything; it just offers the opportunity to preventDefault().

Does your stack use dispatchMessage()? This is asynchronous and allows fetching resources to start before you can prevent.

Have you read http://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/SafariExtensionGuide.pdf#page=88? It offers a synchronous approach (pp. 91-92)

ps
I would have added this as a comment rather than an answer but I cannot yet add comments

Upvotes: 2

Related Questions