I reroute certain websites through a proxy with a proxy.pac file.

It basically looks like this:

if (shExpMatch(host, "www.youtube.com"))
    { return "PROXY proxy.domain.tld:8080; DIRECT" }
if (shExpMatch(host, "youtube.com"))
    { return "PROXY proxy.domain.tld:8080; DIRECT" }

At the moment about 125 sites are rerouted using this method. However, I plan on adding quite a few more domains to it, and I'm guessing it will eventually be a list of 500-1000 domains.

It's important to not reroute all traffic through the proxy.

What's the best way to keep this file optimized, performance-wise ?

Thanks

link|improve this question

79% accept rate
feedback

2 Answers

up vote 0 down vote accepted

As usual: hashes or trees.

I'd use hashing: extract the first one (or more chars) of the requested domain name (stripping "www." as well) to select corresponding pattern list.

link|improve this answer
Could you give me an example? – Tuinslak Mar 10 '11 at 11:32
Most straight one: host[0] would give you the very first char of it. Now you can use it as switch key: switch (host[ 0 ]) { case 'g': if ... else if () and so on (if's are from you example). – poige Mar 10 '11 at 13:05
feedback

If you are just checking for equality use '==' for comparison. The shExpMatch function allows for shell expressions (* and ? in their DOS shell meanings) so the second argument has to be parsed. The script runs in the browser, once (or less) per request so performance is not an issue but it makes the code clearer if you write what yuo mean.

I would also use a variable to hold the proxy expression. It probably won't save run-time storage as the repeated literal is probably re-used, but it will make the code easier to read.

There is good info on http://www.proxypacfiles.com/ including examples and lessons learned.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.