# DNS-dependent rule placed before string rules

Source: https://findproxyforurl.net/rules/expensive-before-cheap/ · last updated 2026-10-14

Rule PAC-P005 (`expensive-before-cheap`), severity low, category: Performance.

Rules execute in source order and the first match returns. When a DNS-dependent rule precedes string rules, requests that a later cheap rule would have decided still depend on DNS. The first request to each name waits for the lookup, and every request waits when DNS does not answer.

## Why it matters

`isPlainHostName`, literal comparisons, `shExpMatch` and `dnsDomainIs` cost microseconds;
`dnsResolve`, `isResolvable` and `isInNet` on a name cost a resolver round trip. Putting
the cheap, frequently matching rules first means most requests never reach the expensive
ones. This is the ordering rule; PAC-P001 is the stronger statement that the expensive rules
should ideally not exist.


## How to fix

Move isPlainHostName, host == and suffix/glob rules above any DNS-dependent rule. An isInNet call that only runs after a test that the host is an IP address (shExpMatch(host, "10.*") &&, an anchored regular expression such as /^[0-9.]+$/, the same test kept in a variable or helper function, or host.match(...) != null) does no DNS lookup for ordinary names and is not reported.

## Bad

```js
function FindProxyForURL(url, host) {
  var ip = dnsResolve(host);
  if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
    return "DIRECT";
  }
  if (isPlainHostName(host)) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```

## Good

```js
function FindProxyForURL(url, host) {
  if (isPlainHostName(host)) {
    return "DIRECT";
  }
  var ip = dnsResolve(host);
  if (ip && isInNet(ip, "10.0.0.0", "255.0.0.0")) {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```
