We have a situation where our contrib modules are being loaded for the anonymous user, but they are not needed. As a result, we are seeing higher page load times. We tried using hook_js_alter
in a custom module with the code below. What is the proper way to not load the js files we don't need for the anonymous user?
mymodule_js_alter($javascript) {
$javascript['somefile']['weight']=50;
$javascript['somefile']['scope']=bottom; //region for bottom of the page
}
Current code:
function mymodule_js_alter(&$javascript) {
if(user_is_anonymous()){
unset($javascript['sites/all/modules/contrib/autocomplete/autocomplete.js']);
}
}