<commit_before>###**
AJAX acceleration
=================

Unpoly comes with a number of tricks to shorten the latency between browser and server.

\#\#\# Server responses are cached by default

Unpoly caches server responses for a few minutes,
making requests to these URLs return instantly.
All Unpoly functions and selectors go through this cache, unless
you explicitly pass a `{ cache: false }` option or set an `up-cache="false"` attribute.

The cache holds up to 70 responses for 5 minutes. You can configure the cache size and expiry using
[`up.proxy.config`](/up.proxy.config), or clear the cache manually using [`up.proxy.clear()`](/up.proxy.clear).

Also the entire cache is cleared with every non-`GET` request (like `POST` or `PUT`).

If you need to make cache-aware requests from your [custom JavaScript](/up.syntax),
use [`up.request()`](/up.request).

\#\#\# Preloading links

Unpoly also lets you speed up reaction times by [preloading
links](/a-up-preload) when the user hovers over the click area (or puts the mouse/finger
down). This way the response will already be cached when
the user releases the mouse/finger.

\#\#\# Spinners

You can listen to the [`up:proxy:slow`](/up:proxy:slow) event to implement a spinner
that appears during a long-running request.

\#\#\# More acceleration

Other Unpoly modules contain even more tricks to outsmart network latency:

- [Instantaneous feedback for links that are currently loading](/a.up-active)
- [Follow links on `mousedown` instead of `click`](/a-up-instant)

@module up.proxy
###
up.proxy = do ->

  u = up.util

  ###**
  @property up.proxy.config
  @param {number} [config.preloadDelay=75]
    The number of milliseconds to wait before [`[up-preload]`](/a-up-preload)
    starts preloading.
  @param {number} [config.cacheSize=70]
    The maximum number of responses to cache.
    If the size is exceeded, the oldest items will be dropped from the cache.
  @param {number} [config.cacheExpiry=300000]
    The number of milliseconds until a cache entry expires.
    Defaults to 5 minutes.
  @param {number} [config.slowDelay=300]
    How long the proxy waits until emitting the [`up:proxy:slow` event](/up:proxy:slow).
    Use this to prevent flickering of spinners.
  @param {number} [config.maxRequests=4]
    The maximum number of concurrent requests to allow before additional
    requests are queued. This currently ignores preloading requests.

    You might find it useful to set this to `1` in full-stack integration
    tests (e.g. Selenium).

    Note that your browser might [impose its own request limit](http://www.browserscope.org/?category=network)
    regardless of what you configure here.
  @param {Array<string>} [config.wrapMethods]
    An array of uppercase HTTP method names. AJAX requests with one of these methods
    will be converted into a `POST` request and carry their original method as a `_method`
    parameter. This is to [prevent unexpected redirect behavior](https://makandracards.com/makandra/38347).
  @param {Array<string>} [config.safeMethods]
    An array of uppercase HTTP method names that are considered [safe](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1).
    The proxy cache will only cache safe requests and will clear the entire
    cache after an unsafe request.
  @param {Function(string): Array<string>} [config.requestMetaKeys]
    A function that accepts a URL and returns an array of [`up.Request`](/up.Request) property names
    that are sent to the server. The server may return an optimized response based on these properties,
    e.g. by omitting a navigation bar that is not targeted.

    Two requests with different `serverFields` are considered cache misses when [caching](/up.proxy) and
    [preloading](/up.link.preload). To improve cacheability, you may configure a function that returns
    fewer fields.

    By default the following properties are sent to the reserver:

    - [`up.Request.prototype.target`](/up.Request.prototype.target)
    - [`up.Request.prototype.failTarget`](/up.Request.prototype.failTarget)
    - [`up.Request.prototype.context`](/up.Request.prototype.context)
    - [`up.Request.prototype.failContext`](/up.Request.prototype.failContext)
    - [`up.Request.prototype.mode`](/up.Request.prototype.mode)
    - [`up.Request.prototype.failMode`](/up.Request.prototype.failMode)
  @stable
  ###
  config = new up.Config ->
    slowDelay: 300
    cacheSize: 70
    cacheExpiry: 1000 * 60 * 5
    wrapMethods: ['PATCH', 'PUT', 'DELETE']
    safeMethods: ['GET', 'OPTIONS', 'HEAD']
    concurrency: 4
    preloadQueueSize: 5
    preloadEnabled: 'auto'
    preloadTimeout: 10
    preloadMaxResponseTime: 750
    preloadSampleSize: 3      # set to 0 to prevent sampling<commit_msg>Preload timeout is 10 seconds, not 10 ms<commit_after>###**
AJAX acceleration
=================

Unpoly comes with a number of tricks to shorten the latency between browser and server.

\#\#\# Server responses are cached by default

Unpoly caches server responses for a few minutes,
making requests to these URLs return instantly.
All Unpoly functions and selectors go through this cache, unless
you explicitly pass a `{ cache: false }` option or set an `up-cache="false"` attribute.

The cache holds up to 70 responses for 5 minutes. You can configure the cache size and expiry using
[`up.proxy.config`](/up.proxy.config), or clear the cache manually using [`up.proxy.clear()`](/up.proxy.clear).

Also the entire cache is cleared with every non-`GET` request (like `POST` or `PUT`).

If you need to make cache-aware requests from your [custom JavaScript](/up.syntax),
use [`up.request()`](/up.request).

\#\#\# Preloading links

Unpoly also lets you speed up reaction times by [preloading
links](/a-up-preload) when the user hovers over the click area (or puts the mouse/finger
down). This way the response will already be cached when
the user releases the mouse/finger.

\#\#\# Spinners

You can listen to the [`up:proxy:slow`](/up:proxy:slow) event to implement a spinner
that appears during a long-running request.

\#\#\# More acceleration

Other Unpoly modules contain even more tricks to outsmart network latency:

- [Instantaneous feedback for links that are currently loading](/a.up-active)
- [Follow links on `mousedown` instead of `click`](/a-up-instant)

@module up.proxy
###
up.proxy = do ->

  u = up.util

  ###**
  @property up.proxy.config
  @param {number} [config.preloadDelay=75]
    The number of milliseconds to wait before [`[up-preload]`](/a-up-preload)
    starts preloading.
  @param {number} [config.cacheSize=70]
    The maximum number of responses to cache.
    If the size is exceeded, the oldest items will be dropped from the cache.
  @param {number} [config.cacheExpiry=300000]
    The number of milliseconds until a cache entry expires.
    Defaults to 5 minutes.
  @param {number} [config.slowDelay=300]
    How long the proxy waits until emitting the [`up:proxy:slow` event](/up:proxy:slow).
    Use this to prevent flickering of spinners.
  @param {number} [config.maxRequests=4]
    The maximum number of concurrent requests to allow before additional
    requests are queued. This currently ignores preloading requests.

    You might find it useful to set this to `1` in full-stack integration
    tests (e.g. Selenium).

    Note that your browser might [impose its own request limit](http://www.browserscope.org/?category=network)
    regardless of what you configure here.
  @param {Array<string>} [config.wrapMethods]
    An array of uppercase HTTP method names. AJAX requests with one of these methods
    will be converted into a `POST` request and carry their original method as a `_method`
    parameter. This is to [prevent unexpected redirect behavior](https://makandracards.com/makandra/38347).
  @param {Array<string>} [config.safeMethods]
    An array of uppercase HTTP method names that are considered [safe](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1).
    The proxy cache will only cache safe requests and will clear the entire
    cache after an unsafe request.
  @param {Function(string): Array<string>} [config.requestMetaKeys]
    A function that accepts a URL and returns an array of [`up.Request`](/up.Request) property names
    that are sent to the server. The server may return an optimized response based on these properties,
    e.g. by omitting a navigation bar that is not targeted.

    Two requests with different `serverFields` are considered cache misses when [caching](/up.proxy) and
    [preloading](/up.link.preload). To improve cacheability, you may configure a function that returns
    fewer fields.

    By default the following properties are sent to the reserver:

    - [`up.Request.prototype.target`](/up.Request.prototype.target)
    - [`up.Request.prototype.failTarget`](/up.Request.prototype.failTarget)
    - [`up.Request.prototype.context`](/up.Request.prototype.context)
    - [`up.Request.prototype.failContext`](/up.Request.prototype.failContext)
    - [`up.Request.prototype.mode`](/up.Request.prototype.mode)
    - [`up.Request.prototype.failMode`](/up.Request.prototype.failMode)
  @stable
  ###
  config = new up.Config ->
    slowDelay: 300
    cacheSize: 70
    cacheExpiry: 1000 * 60 * 5
    wrapMethods: ['PATCH', 'PUT', 'DELETE']
    safeMethods: ['GET', 'OPTIONS', 'HEAD']
    concurrency: 4
    preloadQueueSize: 5
    preloadEnabled: 'auto'
    preloadTimeout: 10 * 1000
    preloadMaxResponseTime: 750
    preloadSampleSize: 3      # set to 0 to prevent sampling
{'fraction_non_alphanumeric': 0.10521903164954936, 'fraction_numerical': 0.012995179207713268, 'mean_word_length': 3.9241486068111455, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7380183', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2693, 'n_words': 1069}