Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Can I use JS to add async to a script tag in an iframe in such a way that it will actually affect the script page loading?

It seems that the Stripe JavaScript is adding nearly 1/2 a second of main-thread blocking to my site. According to the Stripe documentation, it's totally fine to either async or defer their JS. In fact, they say that if you include it through npm it does this automatically. This is probably what I would have done if I were implementing this on my own, but I'm using Stripe through a WordPress plugin that, whatever they're doing, is pulling the Stripe JS in through an iFrame, and not setting async:

<iframe name="__privateStripeController5481" ...>
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <script src="https://js.stripe.com/v3/fingerprinted/js/shared-0950781806f615c0693abdcbbb4bfc19.js"></script>
            <script src="https://js.stripe.com/v3/fingerprinted/js/controller-842819e3871bc12ac5b51fa16b375c03.js"></script>
        </head>
        <body></body>
    </html>
</iframe>

I'm thinking there should be some way to fix this, without waiting on the plugin developers to do it on their own. My idea is to do something like:

document.getElementById('ifrm').onload = function() {
    const ifrm = document.getElementById('ifrm'); 
    const scripts = ifrm.contentDocument? 
                    ifrm.contentDocument: ifrm.contentWindow.document.getElementsByTagName('script');
    for (const element of scripts) {
        element.hasAttribute('async') ? {} : element.setAttribute('async', '');
    }
};

But onload, will, I'm pretty sure, be way too late. Is there a way to accomplish this modification such that it happens early enough that the scripts in the iFrame end up being non-blocking?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No, you can't change how the script tag is processed after the browser has read it from the HTML and started processing it. (Not least because your page and the iframe are running on the same one main UI thread — the very thread being blocked by that script tag.)

You'll have to modify the plugin's code. (And perhaps do a PR to get it adopted by the plugin project maintainers.)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!