I guess you are adding the script with respect to Master page location. If so change it to always point from the root by using ~.
Lets take this is your folder structure
<script>
<Subfodler1>
<Subfodler2>
-> Master Page
From root the script file a.js will be referred as /script/a.js. This will work for files in root but fails when you access a page from subfolder1. Because if will try to locate script within subfolder1 which doesn't exist. So to make accessible globally we need to change the script path in master page to point to root (~). i.e. ~/script/a.js so irrespective of the page location the script will be always loaded from root.