Internet Search

How to remove query string from static resource?

Put this code on yourthemename.theme
Work for Drupal 8
Original Source: https://stackoverflow.com/questions/48561463/how-to-remove-query-string-...

Before do that, see this article for detailhttps://drupal.stackexchange.com/questions/161095/remove-query-strings-f...

Drupal 8 have a module to handel this but it is this project is not covered by the security advisory policy: https://www.drupal.org/project/remove_querystring_from_static_resource


use Drupal\Core\Asset\AttachedAssetsInterface;

    /**
    * Implements hook_css_alter().
    */

    function bootstrap_css_alter(&$css, AttachedAssetsInterface $assets){
        foreach ($css as &$file) {
            if ($file['type'] != 'external') {
            $file['type'] = 'external';
            $file['data'] = '/' . $file['data'];
            }
        }

     }


     /**
     * Implements hook_js_alter().
     */

    function bootstrap_js_alter(&$javascript, AttachedAssetsInterface $assets){

        foreach ($javascript as &$file) {
            if ($file['type'] != 'external') {
            $file['type'] = 'external';
            $file['data'] = '/' . $file['data'];
            }
        }
    }