Preferred way to exclude pages from including a script

Use dynamic imports. Take a look at these: