Proxy.pac file performance optimization

javascriptpacPROXY

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

Best Answer

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.