0

I am trying to fetch the jquery from S3 bucket as a fallback. Not sure why the javascript is not getting triggered.

    <script type="text/javascript">
      function helloWorld () {
        console.log('window.jQuery', window.jQuery)
        if (!window.jQuery) {
          document.write(
            '<script src="https://xxxxxxxx.s3.eu-central-1.amazonaws.com/assets/libs/jquery-3.6.1.min.js"></script>'
          )
        }
      }
      helloWorld()
    </script>

I have tried IIFEs, directly keeping the if condition inside script tag like:

    <script type="text/javascript">
      if (!window.jQuery) {
        document.write(
          '<script src="https://xxxxxxxx.s3.eu-central-1.amazonaws.com/assets/libs/jquery-3.6.1.min.js"></script>'
        )
      }
    </script>

or,

    <script type="text/javascript">
      (function () {
        if (!window.jQuery) {
          document.write(
            '<script src="https://xxxxxxxx.s3.eu-central-1.amazonaws.com/assets/libs/jquery-3.6.1.min.js"></script>'
          )
        }
      })()
    </script>

I am using content-security-header and this domain has been included there. Also, I have added this script in all the places in an HTML (in head, in body, top, bottom everywhere :P)

When I am directly adding it as below:

<script src="https://xxxxxxxx.s3.eu-central-1.amazonaws.com/assets/libs/jquery-3.6.1.min.js"></script>

It is working perfectly fine.

Lastly, i have also tried adding/removing type="text/javascript".

Deepak Negi
  • 214
  • 4
  • 11

0 Answers0