Jump to content

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

Recommended Posts

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?


Link to comment
  • Replies 1
  • Created
  • Last Reply

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


This topic is now archived and is closed to further replies.

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.