Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
popsovy

Type="module" fails on mobile devices for custom scripts

Question

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.

Edited by popsovy
retag

Share this post


Link to post

1 answer to this question

Recommended Posts

  • 0

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>


Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...