Saturday, 15 August 2015

javascript - How to do lazy loading of network HTTP request or block and re-initiate when required in Firefox Extension? -



javascript - How to do lazy loading of network HTTP request or block and re-initiate when required in Firefox Extension? -

i working on project in prioritizing http requests of resource loading. accomplish reordering of http requests need either delay http requests send out or either cancel them , re-initiate them later.

following code snippet can used cancel http request in firefox extension.

observe: function(asubject, atopic, adata) { if (atopic == 'http-on-modify-request') { ..... asubject.cancel(components.results.ns_binding_aborted); .... } }

but, there way delay (lazy loading of resources) http request or re-initiate http requests canceled during web page parsing above code.

first of all, cannot cancel requests , re-initiate them later. looses "binding" information, i.e. request belongs document (or dependent resource). e.g. canceling image request , re-initiating later not automatically tell document (loader) request belongs image element. please note there background requests not initiated document loading , have no document/window attached, update pings or other add-ons doing api requests or downloading files (just mentioning because lot of people forget when writing code dealing http requests @ such low level).

there 2 ways can think of might work you:

use nsisupportspriority channels and/or load groups. http connection scheduler uses internally. possible though piece of code (firefox document loader, other add-ons) uses api after phone call , reverses setting. you'll need business relationship in implementation. you can utilize nsirequest.suspend()/.resume(), may cause connection, if any, dropped in meantime, might cause problems web-apps issue links valid access once. , iirc there buggy scenarios confuse connection scheduler (but can't remember bug numbers atm).

for request types, might feasible cancel , re-initiate, though. e.g. can cancel image request , utilize same mechanism driving "reload image" menu item. won't work (properly or @ all) document requests, script requests, etc.

javascript http firefox firefox-addon

No comments:

Post a Comment