简体   繁体   中英

How to get the compressed file name in Drupal?

After compressing the JS file in Drupal I got a randomly JS file name.

My question how I can get this file name to add it to my javascript?

Drupal code: import and compress

<?php drupal_add_js(drupal_get_path('theme', 'mytheme') . 'mybigfile.js'); ?>

Random file name Result:

js_2KQpJNjjupC1Beoweoqpok2JCXhe0sJ6YBllaRDUXYQ.js

Trying to Call the mybigfile.js file:

<script>
telInput.intlTelInput({
      validationScript: "mybigfile.js"
    });
</script>

As far as I know, you can not get the name of the concatenated JavaScript file generated by Drupal using PHP.

Your best option would be to avoid your JavaScript file mybigfile.js from being concatenated and compressed. Then you can apply your validation script by calling the file name.

You will have to set the preprocess property to false inside drupal_add_js $options array, to prevent the file from being aggregated.

drupal_add_js(drupal_get_path('theme', 'mytheme') . '/mybigfile.js', array(
    'type'      => 'file',
    'preprocess'=> false,
));

Update

If you want to compress a single JavaScript file, you have the option to use AdvAgg API.

Unfortunately, I can't find any documentation for how to do that. But you start with the following:

  1. download and install advagg and enable the submodule advagg_js_compress .

  2. inside the advagg_js_compress submodule folder, find the file advagg_js_compress.advagg.inc and open in your text editor. Here you can find a few helper functions that will help you compressing your JavaScript file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM