- I tried reading you code... way too messy for me get a handle on it. Probably when you pasted it in the standard text box. There is an button on the toolbar for code 7th one over. It would be very helpful if you use it... at least your indentions would be retained. Even pasting in my editor was still too much.
- I see where the the html does the <script> but no explicit handling. Guess relying on file name checked agains SPIFFs exists.
- I also don't see your output. Does it hit "Sent file" or "File Not Found" messages?
- Have you also used the F12 browser debugger to see Network traffic... it will tell if it tried to ask for the script as you expect and where the issue might be.
- And lastly... do you really want to do your own web server for the experience/fun or do you really want to get on with your core project. My server library has charting library built-in... and your whole problem of sending files include your markup and js files can be handled by just dragging and dropping on the Admin file manager. Probably could do most of you program with less than 30 lines of code in the Sketch including the webserver library calls.
w/ GUI Admin Client, Drag & Drop File Manager, OTA Built-In, Access Point Manager,
Performance Metrics, Web Socket Comms, App API, All running on ESP8266...
Even usable on ESP-01S --- Please check it out!
https://inqonthat.com/inqportal-the-three-line-promise/
https://InqOnThat.com/inqportal