Proxy Automatic Config (PAC) File Tips
Wednesday, 11. April 2007, 13:26:33
I was recently involved in our corporate overhaul of our proxy automatic config (.pac) file. Below are some tips if you ever have to do the same. Since some older clients or custom apps may have poor JavaScript support, or may be considered non-standard, thus:
* Always check url and host parameters prior to using them.
* Validate all built-in JS functions exist prior to calling them.
* Keep the .pac file size as small as possible, to improve download speed.
* Keep comments to a minimum, per above.
* Since "return" is immediate, avoid using "else" for "if" statements, per above.
* Single-line if() statements do not require begin { and end } brackets, per above.
* Avoid calling isResolvable(), dnsResolve(), and isInNet() functions, due to DNS performance issues.
* Check simple rule exceptions first.
* Place high-probability checks early-on and nearest top.
* Avoid using any external or global vars/functions.
* Since .pac files are text and can be downloaded/viewed by anyone, avoid revealing secrets.
* For security reasons, avoid referencing clients by IP addresses.
* Use efficient regular expressions, and avoid capturing matches if you don't reference them later on.
* To avoid typos, only declare unique return strings once (near top for easy maintenance).
* When possible, sort lists of IP addresses and/or domains to ease future maintenance efforts.
* Try to group common return values into single conditional if() checks.
* For single proxy server environments, return the proxy's static IP address to bypass DNS lookup overhead.
* Ensure your text file encoding is proper for your hosting server environment.
* If checking IPs or domains, avoid protocol-specific string comparisons against the url parameter.
* Randomized proxy load-balancing via pac files is not recommended.
* Keep in mind that server access is either proxied or not. Thus, checking ports and protocols is typically not required.
* Be sure to check all conditions and exceptions listed in your .pac file prior to deployment.
* Obviously, ensure your JavaScript is error-free prior to deployment.
Hope this helps. Enjoy.
* Always check url and host parameters prior to using them.
* Validate all built-in JS functions exist prior to calling them.
* Keep the .pac file size as small as possible, to improve download speed.
* Keep comments to a minimum, per above.
* Since "return" is immediate, avoid using "else" for "if" statements, per above.
* Single-line if() statements do not require begin { and end } brackets, per above.
* Avoid calling isResolvable(), dnsResolve(), and isInNet() functions, due to DNS performance issues.
* Check simple rule exceptions first.
* Place high-probability checks early-on and nearest top.
* Avoid using any external or global vars/functions.
* Since .pac files are text and can be downloaded/viewed by anyone, avoid revealing secrets.
* For security reasons, avoid referencing clients by IP addresses.
* Use efficient regular expressions, and avoid capturing matches if you don't reference them later on.
* To avoid typos, only declare unique return strings once (near top for easy maintenance).
* When possible, sort lists of IP addresses and/or domains to ease future maintenance efforts.
* Try to group common return values into single conditional if() checks.
* For single proxy server environments, return the proxy's static IP address to bypass DNS lookup overhead.
* Ensure your text file encoding is proper for your hosting server environment.
* If checking IPs or domains, avoid protocol-specific string comparisons against the url parameter.
* Randomized proxy load-balancing via pac files is not recommended.
* Keep in mind that server access is either proxied or not. Thus, checking ports and protocols is typically not required.
* Be sure to check all conditions and exceptions listed in your .pac file prior to deployment.
* Obviously, ensure your JavaScript is error-free prior to deployment.
Hope this helps. Enjoy.

amg7 # 21. January 2009, 18:06
I am new at this but very interested. Would you mind a few questions?
Lee Harvey # 22. January 2009, 00:59