DNS in PAC files: what isInNet and dnsResolve really cost

Published · updated

The most common performance problem in PAC files is a line that looks like simple arithmetic, isInNet(host, "10.0.0.0", "255.0.0.0"). When host is a name, the browser has to look that name up in DNS before it can open the connection. Caches make most of these lookups cheap; a slow DNS server, many different names or a laptop outside the company network make them expensive.

A DNS function makes the route depend on DNS

The browser calls FindProxyForURL before every connection. The helper functions dnsResolve, isResolvable and isInNet with a host name each ask the resolver, which is the part of the browser or of the operating system that gets addresses from the DNS server, and the script waits for the answer (PAC-P001).

isInNet(host, …) hides the lookup. In Chromium’s and Firefox’s helper library it calls dnsResolve whenever its first argument is not already an IP address (source: code, Chromium pac_js_library.h and Firefox ascii_pac_utils.js, verified 2026-10-14; PAC-P002).

What one lookup costs depends on whether an answer for the name is already stored. Usually it is, because a page loads many objects from the same few names, and then the lookup costs almost nothing. The cost becomes real in three cases, which are described further down: many different names in one run of the script, a DNS server that does not answer, and a mix of dnsResolve and dnsResolveEx for the same name in Chrome and Edge.

The engines also wait in different ways. In the table below, WinHTTP is the part of Windows that services, Windows Update and many programs use to find their proxy, and pactester is the command-line tester built on the open-source pacparser library.

EngineHow the script waits for a DNS answer
Chrome, Edge (Chromium)When the answer is not at hand, the script is stopped, the name is looked up, and FindProxyForURL runs again from the start. Each new name can therefore mean one more run (source: code, Chromium 155, and lab, Chromium 145 and Edge 155, verified 2026-10-14).
FirefoxThe script runs once and waits on each lookup (source: code, verified 2026-10-14).
Windows (WinHTTP)The script runs once and waits on each call (source: lab, Windows 11, verified 2026-10-14).
pactester (pacparser)The script runs once and waits on each call (source: code, verified 2026-10-14).

Only the first request to a name sends a DNS query; caches answer the rest

A web page loads many objects, and the PAC script runs for each request. That does not mean one DNS query per request. Only the first request to a host name makes the resolver ask the DNS server. Repeats inside the same run of the script, and later requests to the same name, are answered from a cache until the stored answer expires. Then the next request asks again.

The lab counted the queries on Windows 11 on 2026-10-14 (source: lab):

  • A script that called isInNet(host, …) 100 times and dnsResolve(host) 50 times for the same name in one run sent one query to the DNS server in Edge 155, Firefox 157 and WinHTTP. Edge sent a second query of its own because it looks the name up again to open the connection, and Firefox also sent a second query for the name.
  • A page with 50 objects from one host name cost one or two queries for the whole page. The next queries came only after the stored answer had expired.
  • pactester 1.5.3 on Linux, on a system without a caching DNS service, sent 150 queries for the 150 calls, because pacparser keeps no answers of its own (source: lab, and code, pacparser.c).

How long each engine keeps a DNS answer

Two terms are needed for the table. The TTL (time to live) is the number of seconds the DNS server says an answer may be kept. NXDOMAIN is the DNS server’s answer that a name does not exist. A DNS server that “does not answer” sends nothing at all, which is what a laptop outside the company network sees when the script asks for an internal name and the internal DNS server cannot be reached. Chrome and Edge behave differently depending on whether they use their own DNS client or the resolver of the operating system; the section on that choice comes further down.

EngineWhere the answer is keptSuccessful answerName does not existDNS server does not answerSame name again in one runDifferent names in one run
Chrome, Edge (Chromium 155)a table for the current request, then the browser’s DNS cache, and under it the system’s cache60 s, whatever the TTL; with the browser’s own DNS client the TTL, but at least 60 sfor the current request only; after that the Windows DNS cache answers. With the browser’s own DNS client, every new request asks the DNS server and then Windows againonly for the current request; the next request waits again, about 12 s each time; with the browser’s own DNS client and plain DNS 3 s more, because the own client tries first and then hands the name to Windows (up to 10 s more after many slow answers)answered from the table20; after that lookups fail without asking
Firefox 157the browser’s DNS cache; nothing in the PAC enginethe TTL on Windows, 60 s on Linux and macOS; then up to 600 s of the old answer while it asks again in the background60 s60 sanswered from the browser’s cacheno limit
Windows (WinHTTP)the Windows DNS cache; nothing in the PAC enginethe TTLkept by the Windows DNS cache (how long was not measured)not kept: every call waits again, also inside one runanswered from the Windows DNS cacheno limit seen
pactester (pacparser 1.5.3)nowhere in pacparser; only in a caching DNS service of the system, if there is onenot keptnot keptnot kept: about 10 s per call with the Linux default settingsa new query for every callno limit

Sources, all verified 2026-10-14. Chromium: code at tag 155.0.8059.83, the table and the limit in proxy_resolver_v8_tracing.cc and the 60 s in host_resolver_manager_job.cc, and lab with Edge 155. Firefox: code at FIREFOX_157_0_RELEASE, ProxyAutoConfig.cpp, nsHostResolver.cpp and the settings network.dnsCacheExpiration and network.dnsCacheExpirationGracePeriod in StaticPrefList.yaml, and lab with Firefox 157. Windows: lab, Windows 11; the rows for names that do not exist and for a DNS server that does not answer were measured again on 2026-10-16 with the same results. pacparser: code at v1.5.3 and lab. The row for Chrome and Edge with their own DNS client was measured on 2026-10-15 (lab, Edge 155). For the short TTL and for the DNS server that does not answer, Edge’s own client sent its queries by DNS over HTTPS (the same queries, carried inside HTTPS requests) to a test server: answers with a TTL of 0 or 10 seconds were asked for again only after 60 seconds, and an answer with a TTL of 90 seconds after 90 seconds. The own client with plain DNS against a DNS server that does not answer was measured on 2026-10-16 (lab, Edge 155, Windows 11); the section on the silent DNS server below has the figures.

An IP address in the URL costs no lookup, and no PAC function asks for a reverse lookup

  • When the URL contains an IP address instead of a name, isInNet(host, …) compares that address directly and nobody is asked. In the page test above, 50 objects loaded from an IP address caused no DNS query in any engine (source: code and lab, verified 2026-10-14).
  • No PAC function makes a reverse lookup, which is the question “which name belongs to this address?” (a PTR query in DNS terms). dnsResolve, isResolvable and isInNet only look names up forwards, from name to address, and no engine sent a reverse query in the lab (source: code and lab, verified 2026-10-14).
  • myIpAddress() makes no DNS lookup in Chrome, Edge and Firefox. These browsers read the computer’s own address from the network connection towards the internet and fall back to a lookup of the computer’s own name only when that fails (source: code, Chromium proxy_auto_config_library.cc and Firefox ProxyAutoConfig.cpp, verified 2026-10-14; this was not measured in the lab). pactester works its address out from the computer’s name unless you set it with pactester -c.

What really costs time with DNS in a PAC file

Many different names in one run make Chrome and Edge run the script again and again

Each different name is its own lookup. Chrome and Edge also stop the script at every name whose answer is not at hand and run it again from the start once the answer has arrived. A request whose script resolved 20 different names ran the script about 21 times; over a page load the lab counted 105 runs of the script for 20 DNS queries (source: lab, Edge 155, verified 2026-10-14).

After 20 different names in one run, Chrome and Edge stop asking. Every further lookup fails at once: dnsResolve returns null, dnsResolveEx returns "" and isInNet returns false, and the script carries on with those answers (source: code, kMaxUniqueResolveDnsPerExec = 20 in proxy_resolver_v8_tracing.cc; lab, Edge 155, names 21 to 25 returned null without any query, verified 2026-10-14). Firefox, Windows and pactester have no such limit, so a file that resolves many names can pass in pactester and route wrongly in Chrome.

A DNS server that does not answer costs about 12 seconds per lookup on Windows

A name that does not exist is cheap, because the DNS server answers at once and the caches keep that answer. A DNS server that does not answer at all is expensive: on Windows 11 each such lookup waited about 12 seconds before it gave up (source: lab, verified 2026-10-14). Windows sent the question five times in that time, after 0, 1, 2, 4 and 8 seconds, and gave up 4 seconds after the last one. The same test was run again on 2026-10-16, after the left-over DNS server described further down had been removed from the test computer, and every figure in this section came out the same (lab, Windows 11, Edge 155, Firefox 157). How often each engine pays that wait differs:

  • Edge waits once per request. Inside one run the failure is kept, so 10 calls cost one wait, but the next request waits again. This is the same with Edge’s own DNS client: a page whose script looked up one such name sent one query per request and waited 12 seconds each time, 84 seconds for the page, its five pictures and its icon (lab, Edge 155, own client over DNS over HTTPS, 2026-10-15). Twelve seconds is the shortest time Chromium gives a DNS query before it gives up (source: code, features.cc). With plain DNS, the normal case, the own client sends the question, sends it once more after 1 second, gives up after 3 seconds and then hands the name to Windows, which asks again and waits its own time (source: code, two attempts in dns_config.h and no extra wait when Windows is the next step in dns_transaction.cc; lab, Edge 155, Windows 11, 2026-10-16). What the user waits for in total therefore depends on the DNS server the computer asks. In a company network that server often passes the question for an internal zone on to another DNS server. When that one does not answer, the company server sends back a failure (“server failure”) once its own time limit has passed. In the lab, such a server with a limit of 3 seconds sent the failure after 3.6 to 4.5 seconds, and every request waited exactly that long, with Edge’s own client and without it; the extra queries of the own client cost nothing. When the computer’s DNS server sent nothing for a whole minute, every request waited 15 seconds, 3 in Edge’s own client and 12 in Windows, and the page with five pictures took 91 seconds; with the own client switched off it was 12 seconds per request and 73 seconds for the page. Ten calls in one request still cost one wait, and nothing was kept for the next request. An answer that came late but within the wait was used. The wait is not fixed: a new browser gave up after 3 seconds, but the client sets its wait from the answer times it has seen. After answers that took 2.5, 4, 6 and 8 seconds, the second question went out after 2.6, 3.5, 4.0 and then 5.0 seconds, answers that took 9.5 seconds were still used, and a name whose server never answered was given up after 10 seconds instead of 3, so each such request then waited 22 seconds, 10 in Edge’s own client and 12 in Windows (lab, Edge 155, 2026-10-16). Five seconds is the longest wait the code allows after each of the two questions; it takes the wait from almost the slowest answer it has seen (the 99th percentile) and doubles it for the second question (source: code, resolve_context.cc, lines 594 to 622). Edge also opens a connection to the page’s own server ahead of time, once more just after the page’s request has its answer, and runs the script for it; when the script’s lookup had failed, that run asked the DNS server again, but the page did not wait for it (lab, Edge 155, 2026-10-16).
  • Firefox waits once per name and then keeps the failure for 60 seconds, so the following requests do not wait.
  • WinHTTP waits on every call, even inside one run: a script with 10 calls for the same name took 120 seconds for one request.
  • Desktop programs that use WinINet, the Windows network library for programs that follow the Windows proxy settings, wait in the same way. In addition, the first request of such a program, the one that makes it download the PAC file, runs the script twice in a row, so it waits twice: 24 seconds for one lookup instead of 12. The same happens when Windows has forgotten the file after about 6 to 7 minutes without use, and to a request that is still running when Windows downloads a PAC file, its own file on the schedule of about every 10 minutes or the file of another program with a different PAC address. Other requests run the script once (lab, Windows 11, 2026-10-16).
  • pactester waits about 10 seconds on every call with the Linux default settings.

This is the case a company laptop meets outside the office: a rule that resolves an internal name is cheap inside the company network and costs a timeout per request, on WinHTTP per call, everywhere else.

Mixing dnsResolve and dnsResolveEx for one name makes two lookups in Chrome and Edge

dnsResolve asks for IPv4 addresses only and dnsResolveEx for all addresses. Chrome and Edge store the two answers as separate entries, so a script that uses both for the same name asks twice (source: code, host_cache.h, and lab, Edge 155, verified 2026-10-14). The same holds for isResolvable and isResolvableEx. Firefox has no dnsResolveEx at all.

Chrome and Edge often use the Windows resolver instead of their own DNS client

Chrome and Edge contain their own DNS client, which sends queries to the DNS server directly. They use it by default. They use the operating system’s resolver instead when the built-in client is switched off with the policy BuiltInDnsClientEnabled (Chrome, Edge), or when the built-in client cannot handle the system’s DNS settings.

On Windows, one such setting is enough: any rule in the Name Resolution Policy Table (NRPT), which is the Windows list of name endings that are sent to particular DNS servers (source: code, dns_config_service_win.cc, verified 2026-10-14). Company computers with DirectAccess, Always On VPN or a similar VPN client have such rules. Windows can also create rules by itself: a Windows 11 computer in the lab had two that nobody had added (source: lab, verified 2026-10-14). Get-DnsClientNrptPolicy in PowerShell lists the rules on a computer.

Three more settings have the same effect in the same code: a DNS proxy that Windows has registered for a connection, a dial-up or VPN network adapter (also one that is not connected), and two connected network adapters with different lists of DNS servers (source: code, dns_config_service_win.cc, verified 2026-10-15). A Windows 11 computer in the lab had no NRPT rule, no DNS proxy and no VPN adapter, and Edge still did not use its built-in client, also not with --enable-features=AsyncDns. One extra network adapter had kept an IPv6 DNS server from a network it had been connected to before. When that server was taken out of the adapter’s settings, Edge used its built-in client at once, without any switch or policy (lab, Edge 155, 2026-10-15). The same left-over server also slowed down Windows itself: while it was there, every IPv4 lookup of a name that does not exist took 12 seconds, although the main DNS server answered at once. After it was removed, such lookups took a few milliseconds (lab, Windows 11, 2026-10-15). Get-DnsClientServerAddress in PowerShell lists the DNS servers of every adapter. The addresses fec0:0:0:ffff::1 to ::3, which Windows shows for an adapter that has no IPv6 DNS server, do not count (source: code, win_dns_system_settings.cc). No policy or switch makes the built-in client accept such settings; the policy BuiltInDnsClientEnabled can switch it off, but switched on it still steps back (source: code, dns_client.cc).

On the operating system’s resolver, Chrome and Edge keep a successful answer for 60 seconds whatever the TTL, keep no failures beyond the current request, and every lookup they make goes through the Windows DNS cache. With their own client they keep the answer for the TTL, but at least 60 seconds, and send their queries to the DNS server past the Windows cache.

The lab compared the two paths with the same script on the same computer (lab, Edge 155, 2026-10-15). Most results were the same: 150 lookups of one name in one run sent one query, the limit of 20 different names applied, and dnsResolve plus dnsResolveEx for one name sent two queries. Two results differed:

  • A new browser process asks the DNS server again. With the built-in client, the first lookup after the browser started went to the DNS server every time. On the Windows resolver, Windows answered the same lookup from its own cache.
  • A name that does not exist costs two lookups on every request. The built-in client asks the DNS server, gets the answer that the name does not exist, and then hands the same name to the Windows resolver. That second failure is kept for no time at all, so the next request asks both again (source: code, host_resolver_manager_job.cc, and lab). A script that looks up a name which does not exist therefore sends queries to the DNS server on every request.

Why it also fails open

When resolution fails, dnsResolve returns an empty value and isInNet returns false. The rule simply does not match, and the request takes whatever comes next, normally the default route (PAC-X010). On a hostile network the resolver answer is controlled by the attacker, so the routing decision is too. If a name has several addresses, only one of them is compared.

The empty value is not the same everywhere. Chrome, Edge, Firefox and pactester return null from a failed dnsResolve, but WinHTTP returns false (source: lab, Windows 11, verified 2026-10-14). A test such as if (ip === null) or if (ip == null) therefore never fires on Windows. Write if (!ip), which is true for both.

Best practice: decide on the host name first, resolve at most once

Most PAC files can decide everything from the host name. Reorder so that cheap string tests come first (PAC-P005), and use address tests only for IP addresses. A test in front of isInNet that lets only IP addresses through is enough:

if (/^\d+\.\d+\.\d+\.\d+$/.test(host) && isInNet(host, "10.0.0.0", "255.0.0.0")) {
  return "DIRECT";
}

The annotated reference proxy.pac is a complete file built this way, and the page of PAC-P002 lists every form of this test that the checker accepts.

The rules that follow from the measurements above:

  • Check names before addresses. Use isPlainHostName, dnsDomainIs and shExpMatch before any isInNet or dnsResolve, so that most requests are decided without a lookup at all.
  • Do not find the client’s location by resolving an internal name. Outside the company network that lookup waits for a timeout. myIpAddress() is no reliable replacement either: on a computer with several network adapters or a VPN it can return the wrong address (PAC-K013).
  • Resolve few different names. Keep the number of different names resolved in one run small, well under the 20 that Chrome and Edge allow.
  • Resolve once into a local variable inside FindProxyForURL. The reason is not that every call is a new DNS query; for a normal answer it is not. The reasons are these: WinHTTP keeps nothing between the calls of one run, so with a slow or unreachable DNS server every call waits again; pactester and other engines without a cache send a query for every call; and one variable avoids the second Chrome and Edge entry when dnsResolve and dnsResolveEx are mixed (PAC-P004).
  • Test the result with if (!ip), which works in every engine, Windows included.
  • Never keep DNS answers in a variable outside FindProxyForURL. Engines do not promise that such a variable survives from one request to the next, and where it does, it never expires (PAC-K008).
  • Plan for the laptop outside the office. A rule that resolves an internal name is cheap inside the company and costs a timeout per request outside it, on WinHTTP for every call.

If you really must route by the resolved address, do it once, after all string rules:

var ip = dnsResolve(host);
if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
  return "DIRECT";
}
  • isInNet("10.0.0.0", host, "255.0.0.0"): arguments in the wrong order, always false (PAC-C016).
  • An invalid network or mask such as 10.0.0 or 255:255.255.0: always false (PAC-E010).
  • IPv6 networks in isInNet never match. isInNetEx exists only in some engines (PAC-K014).
  • isResolvable(host) as an “is it internal” test: it answers a different question (PAC-P003).

Check your file

The online PAC file tester flags every DNS call on the request path and its position in the file. Set DNS answers in the tester to see how each rule behaves when a name resolves, and when it does not.

Frequently asked questions

Does isInNet do a DNS lookup?

Yes, when the first argument is a host name. isInNet resolves it first and then compares the address with the network and mask. Given an IP address it does no lookup.

Does calling isInNet many times cost many DNS lookups?

No, as long as it is the same name. In Chrome, Edge, Firefox and Windows only the first call for a name sends a query to the DNS server; the other calls are answered from a cache. In a test with 150 calls for one name in one run, each of these engines sent one query. pactester is the exception, because it keeps no cache and asks again for every call unless the system it runs on caches DNS answers. Each different name, however, is a lookup of its own.

How long do browsers cache the DNS answers a PAC file asks for?

Chrome and Edge keep an answer for 60 seconds, or for the time the DNS record allows if that is longer and the browser's own DNS client is in use. Firefox keeps it for the time the record allows on Windows and for 60 seconds on Linux and macOS, and may then serve the old answer for up to 10 more minutes while it asks again in the background. Windows programs that use WinHTTP rely on the Windows DNS cache, which keeps the answer for the time the record allows. When the DNS server does not answer at all, Chrome, Edge and Windows remember nothing, so the next request waits again.

Does a PAC file make reverse DNS lookups?

No. No PAC function asks for the name that belongs to an address. dnsResolve, isResolvable and isInNet look a name up forwards, from name to address, and myIpAddress reads the computer's own address without asking DNS in Chrome, Edge and Firefox.

Why is my PAC file slow?

Usually because it calls dnsResolve, isResolvable or isInNet on a host name on the way to most requests. While DNS answers quickly, caches hide the cost. When the DNS server is slow or cannot be reached, for example on a laptop outside the company network, every lookup waits for a timeout, about 12 seconds on Windows. Decide on the host name string first and run DNS rules only for the few requests that need them, or not at all.

What happens when DNS fails inside a PAC file?

dnsResolve returns an empty value (null in most engines, false in Windows) and isInNet returns false, so the request skips the rule and takes the next one, usually the default route. Routing then depends on the resolver, which fails open.