Switch branches/tags
Nothing to show
Find file History
Pull request Compare This branch is 1 commit ahead, 65 commits behind igrigorik:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Proxy Auto Configuration (PAC)

A proxy auto-config (PAC) file defines how web browsers and other user agents can automatically choose the appropriate proxy server (access method) for fetching a given URL. To create a valid PAC file you simply need to provide a single JavaScript function: FindProxyForURL(url, host). This function is automatically executed by the browser when requests are dispatched.

The URL of the PAC file is either configured manually or determined automatically by the Web Proxy Auto-discovery Protocol.

Example PAC file

function FindProxyForURL(url, host) {
  // our local URLs from the domains below example.com don't need a proxy:
  if (shExpMatch(host, "*.example.com")) {
     return "DIRECT";

  // our local URLs from the domains below example.com don't need a proxy:
  if (shExpMatch(host, "*.google.com")) {
     return "HTTPS localhost:44300";

  // URLs within this network are accessed through
  // port 8080 on fastproxy.example.com:
  if (isInNet(host, "",  "")) {
     return "PROXY fastproxy.example.com:8080";

  // Use a different proxy for each protocol.
  if (shExpMatch(url, "http:*"))  return "PROXY proxy1.domain.com:3128";
  if (shExpMatch(url, "https:*")) return "PROXY proxy2.domain.com:3128";
  if (shExpMatch(url, "ftp:*"))   return "PROXY proxy3.domain.com:3128";

  // All other requests go through port 8080 of proxy.example.com.
  // should that fail to respond, go directly to the WWW:
  return "PROXY proxy.example.com:8080; DIRECT";

For more examples of what you can do with PAC files, use your favorite search engine, and also checkout the individual .pac files in this directory.

Now that you've created your custom PAC file, how do you deploy it? Turns out, all browsers support the proxy auto-discovery protocol (WPAD), which allows us to either (a) manually specify the file, or (b) auto-configure the settings through DNS or DHCP: