If you’re to the point where you need to think about optimizing a PAC file, you probably know what you’re doing and don’t need much help. Some high-level observations:
Don’t focus on making your PAC file shorter – Focus on how to make the browser work less. For example, if you have 75 host exceptions for your internal .company.com domain, write one IF statement that checks dnsDomainIs(host, ".company.com") first, then embed your 75 host checks so that they are only run if the host is in .company.com. Most of your traffic probably goes to the Internet, so if you can avoid 75 unique host checks for .company.com hostnames you’ve saved a lot of processing. There is, of course the network bandwidth tradeoff – Longer and more complex means a larger PAC file to be sent across the network. Try to find a balance that works for you. Example:
if (dnsDomainIs(host, ".company.com") {
if ((host == "zeus.company.com") ||
(host == "frodo.company.com") ||
(host == "zaphod.company.com")) {
return proxy;
}
if ((host == "mail.company.com")) ||
(host == "intranet.company.com") {
return "DIRECT";
}
} // End of hosts in .company.com
If you need to check a lot of IP subnets, try to lump them together as much as possible. Use a single regex to check the host to see if it’s an IP address (described above in the tip on using isInNet(host, …) safely) and then list all of the IP’s you want to compare against. If you need to do a lot of checks for the local IP address, set a variable to myIpAddress() at the top of your PAC file and then use this variable instead of myIpAddress() later. From a CPU load perspective, it takes less cycles to check a variable in memory than it does to perform a system call to get the local IP each time you need to compare it.