0

Is there a way to block a particular line of code from being executed within a third-party website, appearing within an iFrame?

I have an embedded widget which is loading JQuery within the iFrame. I don't need the extra network request, because my site is already loading JQuery.

If I can block only one line of code (in this case, line 77) then I can prevent JQuery from being loaded again.

I imagine this action would take place prior to the iFrame being rendered.

kdpnz
  • 638
  • 6
  • 18
  • 1
    Possible duplicate of [jQuery changing contents of an iFrame](https://stackoverflow.com/questions/9490907/jquery-changing-contents-of-an-iframe) – Obsidian Age Dec 07 '17 at 00:42
  • Ideally I'd like to remove the – kdpnz Dec 07 '17 at 00:45

1 Answers1

1

The same-origin policy prevents you from touching any part of an iframe for a third-party website, so there's nothing you can directly do to prevent that request from being sent out. Even if you could, the iframe and your website have no shared state, so the other website will most likely break because it has no way to access your instance of jQuery. Think of what would happen if you loaded the third-party website in a new tab but blocked the request.

There are, however, a few things you can do to ensure the browser uses a cached copy of the library, which doesn't actually send a request anywhere:

  • If the external library is being loaded from a CDN, there's a good chance some other website has requested that same URL, so that user's browser has a cached copy of it.
  • Since you yourself use jQuery, you could use the other website's same version of jQuery. That way, a user's browser will have a cached copy of the file already from the CDN and no second request will be made.

Otherwise, if the website is using an old version of jQuery that you cannot yourself use or if it is being self-hosted without a CDN, there's nothing else you can do.

Blender
  • 289,723
  • 53
  • 439
  • 496