Git Product home page Git Product logo

xhook breaks jQuery's <script src> functionality about xhook HOT 3 CLOSED

jpillora avatar jpillora commented on June 24, 2024
xhook breaks jQuery's

Comments (3)

jpillora avatar jpillora commented on June 24, 2024

Hi @iameli Just debugged this. So jQuery is parsing the HTML and concluding that you're injecting a script, so in order for it to bind on load events, it translates that into a synchronous XHR+eval. XHook does not support synchronous XHR because I allow asynchronous hooks, I could detect if there are asynchronous hooks, though when it loads - XDomain creates an asynchronous hook, so this would still be broken in the majority of cases. I am throwing an error about this though jQuery is silently throwing it away :(

Since I can't support sync XHR I'll have to close this as "wont fix", though I can offer a workaround.

Instead of jQuery:

$('head').append('<script type="text/javascript" src="script.js">');

Vanilla

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "script.js";
document.querySelector("head").appendChild(script);

This is definitely worth including in the docs.

As a side note, since the world is moving away from IE67, I think people should try to depend less on jQuery. See here.

from xhook.

iameli avatar iameli commented on June 24, 2024

Interesting! TIL that synchronous XHR is a thing.

We're actually using xdomain as part of our project to move into a new API and away from our old jQuery based application, so we're definitely on the same page there. :) I ended up working around it in a very similar fashion -- the project was already including head.js for unrelated reasons so I just ended up using that.

Thanks for looking into it!

from xhook.

jpillora avatar jpillora commented on June 24, 2024

Hey @iameli just an update to this, I've implemented sync requests in XHook to fix a chrome iOS bug so this should resolve some of these issues. Though note, when the request is sync, async hooks must be skipped and this includes XDomain so this just attempts to allow external code to operate correctly, we still can't use XDomain to allow sync crossdomain calls.

from xhook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.