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?