Providing insights on file validation techniques (for educational purposes):
If you are utilizing P5.js based on the tags mentioned in the post, one way to check for the existence of an image is by using the loadImage function. This method allows you to preload the image into a variable and verify if the object exists (refer to the P5 reference for implementation details).
For verifying the presence of a .js (or any other) file, you can consider using either loadBytes or httpGet to attempt loading the file into a variable and subsequently check for its existence as demonstrated in the image example.
Addressing the caching dilemma:
Your objective here essentially revolves around "versioning". As highlighted in the previous comments within the post, devising a robust mechanism for this purpose can be quite arduous, may yield inconsistent results, or potentially nullify the advantages offered by caching.
It's noteworthy that until recently, JavaScript lacked the capability to clear cache (only a few browsers support this feature, however, certain individuals perceive it as a security risk exposing such control to developers). Hence, even after confirming the files' existence, ensuring complete cache clearance across all browsers remains challenging.
One plausible approach could involve versioning the directories housing the files rather than individual files themselves. For instance, each iteration of your "script.js" might have URLs structured as follows:
http://yoururl.com/scripts/1.0.0/script.js -> Version 1.0.0
http://yoururl.com/scripts/2.0.0/script.js -> Version 2.0.0
http://yoururl.com/scripts/3.1.0/script.js -> Version 3.1.0
By aligning this strategy with how browsers handle caching for .HTML files, you can leverage cache benefits for assets (such as js, images, etc.) on your webpage while maintaining consistent folder versions referenced in the base .HTML files.
When employing static HTML pages, the web server automatically appends the "Last Modified" header to your pages, enabling browsers to determine if the cached .HTML file remains unchanged. If no alterations are detected, the browser retrieves the .HTML file from cache; otherwise, it fetches the updated version from the server. However, in the case of dynamic pages, you need to programmatically include the "Last Modified" header.