Removes the has_js cookie.

When a browser renders a page generated by Drupal, a piece of JavaScript is executed which adds a cookie (has_js=1). This allows Drupal to generate different markup depending on whether the user agent is capable of executing JavaScript or not.

This approach has been developed as a part of the Batch API (see #127539: batch - progressive operations (à la update.php)). However, generating different markup depending on characteristics of the user agent breaks page level caching. This is one of the reasons why the has_js cookie was removed from Pressflow and also from Drupal 8 (see #229825: backport "$_COOKIE['has_js'] must die" patch to 7.x).

In Drupal 7 there are some bits of code relying on the has_js cookie (e.g., the Batch API) and therefore removing it unconditionally without providing fallback measures will break that functionality.

This module provides means to specify the conditions under which the cookie is removed. It also allows to enforce a value for the $_COOKIE['has_js'] superglobal in order to fix the behavior of code relying on that value if the cookie was removed.

Configuration

Navigate to Administration » Configuration » Development » Performance

Force JS provides two modes of operation:

Remove for users without an open session

Affected functionality like the batch API typically is not available to anonymous users. Hence it is safe to remove the JavaScript code responsible for setting that cookie as long as there is no session open.

This mode also helps sites behind a caching reverse proxy to increase cacheability, since anonymous requests will then not have any cookies - unless other client side code like analytics and ads spoil them.

Remove for all users but pretend its presence

On sites having advanced page level caching in place which also affects users with an open session (e.g., Authcache or ESI), cookie removal must be performed for all users. Otherwise there is a risk that pages served from the cache will randomly set the cookie on the client - depending on whether or not a session was open on the user agent which originally requested the cached page.

Since the cookie gets removed for all users, it is necessary to pretend the presence of the cookie, otherwise things like the batch API will break.

Project information

Releases