Is it possible to override a single javascript file from a module within a theme or custom module? My specific use would be for Views/js/ajax_view.js - I've had to apply multiple patches to get ajax views to work properly with BEF and panels, and though I'm including documentation for future developers, it seems more foolproof to override within the theme or a custom module.


hook_js_alter() allows you to modify any JS before it is written to the page.
The documentation includes a snippet to replace a core file with an alternate from a module:

function hook_js_alter(&$javascript) {
  // Swap out jQuery to use an updated version of the library.
  $javascript['misc/jquery.js']['data'] = drupal_get_path('module', 'jquery_update') . '/jquery.js';
  • When I dpm($javascript), I don't see any Views-related js that I can edit. I tried this in both my theme template.php and in the .module file for my feature associated with the view. – nkanderson Jan 25 '16 at 20:07
  • Do you know why Views js would not be present when I use dpm? – nkanderson Jan 26 '16 at 19:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.