1

I recently come across a issue where my page was rendering two boostrap.js (Offcourse bad coding). An external Js from a module and another js from twitter bootstrap theme. Its causing some of the other js library to stop working(say bootstrap.multiselect.js). So thought of removing the one of the js by mytheme_js_alter. Below code is working fine to achieve what is want, but with one execption. Sometime its does not work, and after clearing the cache it starts working.

function mytheme_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
  $current_path = \Drupal::service('path.current')->getPath();
  $current_uri = \Drupal::request()->getRequestUri();
  if ($current_path == '/node/777' || $current_uri == '/mypage') {
    $external_bootstrap = 'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js';
    if (array_key_exists($external_bootstrap, $javascript)) {
        $javascript[$external_bootstrap]['data'] = $javascript['https://cdn.jsdelivr.net/npm/bootstrap@3.4.0/dist/js/bootstrap.min.js']['data'];
unset$javascript['https://cdn.jsdelivr.net/npm/bootstrap@3.4.0/dist/js/bootstrap.js']);
    }
  }
}

Has anyone faced same issue of caching? Please suggest any solution to overcome this.

  • Did you end up finding a solution? – ev0lution Jun 7 at 2:07
  • @ev0lution No resolve for caching issue. – Md Eqbal Ahmad Jun 9 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.