popsovy Posted September 10, 2019 Share Posted September 10, 2019 I uploaded a simple javascript file to my Squarespace site using this option . The javascript file contains alert("Hello"); nothing else. If I reference the files from <script src="path to the file"></script> all loads on desktops and on mobile devices. If I reference this file as <script src="path to the file" type="module"></script> it loads in desktop browsers, but in all mobile browsers (tested on iPhones), the script doesn't load. I then created a simple HTML page that referenced this JS file with type="module" and uploaded both files to my ISP. The files served from my ISP loaded fine on mobile devices. This makes me think there is a restriction at Squarespace that only allows type="text/javascript". This is a big limitation because a lot of modern JavaScript frameworks rely on loading javascript based on the type="module" attribute. Could Squarespace change the restrictions placed on serving javascript files to allow type="module" to be served from mobile browser? Thanks. Link to comment
popsovy Posted September 10, 2019 Author Share Posted September 10, 2019 Turns out that the reason for scripts with type="module" not loading in a mobile browser is because by default mobile browsers do not send cookies for this kind of requests. The fix here is to add crossorigin="use-credentials" to the script tag, so your tag should look like this: <script src="path to the file" type="module" crossorigin="use-credentials"></script> Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.