class AssetQueryString

Same name in other branches
  1. 10 core/lib/Drupal/Core/Asset/AssetQueryString.php \Drupal\Core\Asset\AssetQueryString

Stores a cache busting query string service for asset URLs.

The string changes on every update or full cache flush, forcing browsers to load a new copy of the files, as the URL changed.

Hierarchy

Expanded class hierarchy of AssetQueryString

1 file declares its use of AssetQueryString
AssetQueryStringTest.php in core/tests/Drupal/KernelTests/Core/Asset/AssetQueryStringTest.php

File

core/lib/Drupal/Core/Asset/AssetQueryString.php, line 16

Namespace

Drupal\Core\Asset
View source
class AssetQueryString implements AssetQueryStringInterface {
    
    /**
     * The key used for state.
     */
    const STATE_KEY = 'asset.css_js_query_string';
    
    /**
     * Creates a new AssetQueryString instance.
     *
     * @param \Drupal\Core\State\StateInterface $state
     *   State service.
     * @param \Drupal\Component\Datetime\TimeInterface $time
     *   System time service.
     */
    public function __construct(StateInterface $state, TimeInterface $time) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function reset() : void {
        // The timestamp is converted to base 36 in order to make it more compact.
        $this->state
            ->set(self::STATE_KEY, base_convert(strval($this->time
            ->getRequestTime()), 10, 36));
    }
    
    /**
     * {@inheritdoc}
     */
    public function get() : string {
        return $this->state
            ->get(self::STATE_KEY, '0');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AssetQueryString::get public function Gets the query string value. Overrides AssetQueryStringInterface::get
AssetQueryString::reset public function Resets the cache query string added to all CSS and JavaScript URLs. Overrides AssetQueryStringInterface::reset
AssetQueryString::STATE_KEY constant The key used for state.
AssetQueryString::__construct public function Creates a new AssetQueryString instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.