3

I'm looking for some guidance on how to replace requests for a specific javascript file with another file that I'll package with the Firefox addon.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
erikvold
  • 15,988
  • 11
  • 54
  • 98
  • 3
    Do you mean that e.g. some HTML page would try to load http://somesite.com/somefile.js using a ` – vladr Jun 30 '10 at 18:09
  • 2
    I'm very interested in this. Would be great for being able to distribute the CSS/Javascript/Images portions of a web app so as to lighten the load on Users over poor/slow web connections (eg. Africa, Pacific Islands) – Damo Jun 30 '10 at 22:06
  • @Vlad you are correct, it's for ga.js specifically. I want to make an addon to disable GA. – erikvold Jul 01 '10 at 06:04
  • @Damo I was thinking the same thing, could speed up library loading, etc.. – erikvold Jul 01 '10 at 06:05

1 Answers1

4

See How can I implement a content converter in Firefox for all page elements? (its scope is much wider than what you really need -- read on) on how to use registerFactory to register a surrogate HTTP protocol handler, which can then instantiate channels with alternate (e.g. file:///...-type) URIs when newChannel is called with your particualr script's URI.

Community
  • 1
  • 1
vladr
  • 65,483
  • 18
  • 129
  • 130
  • So replace newchannel in `var newchannel = this.savedHttpHandler.newChannel(locationURI);` when locationURI is a ga.js uri? and replace it to a channel for a local copy included with the extension? – erikvold Jul 01 '10 at 06:37
  • 1
    Exactly. Another option would have been to rewrite `` nodes in the DOM, but I think that the protocol factory is simpler and more generic in this case. – vladr Jul 01 '10 at 13:43
  • Thanks this information is helping, I'll be trying it out soon. – erikvold Jul 05 '10 at 23:23