Views Ajax Get

Component ID

2232463

Component name

Views Ajax Get

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

4499

Component created

Component changed

Component body

This module will make your ajax-enabled Views, use GET instead of POST.

Why?
Because GET is much better for caching. If you're using something like Varnish, or Boost, these will not store POST requests.

Views uses the Drupal Ajax framework. This by default uses POST.
While a lot of Ajax inside of Drupal requires POST (the Views admin UI, for example), a view itself doesn't. If you disable Ajax on a View, it will use GET anyway.

How?
This module overrides a core Drupal Ajax JavaScript function (this is sometimes referred to as monkey-patching).

Note
To ensure an Ajax request does not contain any duplicate HTML IDs, CSS and JS files. The Drupal Ajax framework sends through the name of every HTML ID, CSS and JS file in the POST Ajax request (allowing duplicates to be stripped out from the Ajax response).
Due to the size this makes the request, this is not possible when using GET, so this module removes them from the GET request.
Although we have not yet seen this cause any issues, it is something you should be aware of when using this module.
If you do come across any issues because of this, you can set a particular View to be exempt from using GET, by going to admin/config/system/views_get_ajax (this is opt-out as opposed to opt-in).

@See #956186: Allow AJAX to use GET requests which is an issue to fix this in core, while still retaining all the current functionality.

Also, if you are using Varnish with the Four Kitchens VCL, or something similar, you will need to remove the following line from vcl_recv
req.url ~ "^.*/ajax/.*$" ||
Otherwise, Varnish will not cache the Views Ajax responses.

Drupal 8 version

There is now a dev release for views ajax get on Drupal 8.
Please note there is currently an issue that means render caching must be disabled. See #2913754: Enabling render cache leads to incorrect results.

There is also a known incompatibility with other modules that modify the views ajax url, e.g. views ajax history. See #2913388: Disable URL replacement on GET requests in Drupal.Ajax.prototype.beforeSend