jQuery and sharedworkers

224 Views Asked by At

Am I right in saying that jQuery can't be used inside a Sharedworker. Shared workers operate outside of a browser tab and don't have access to window/document (that I'm aware off) so I don't think jQuery will work as again I think it needs access to the window object.

The above being the case - is there any methods or structure that can be used to modify the jQuery code so that it can be loaded without access to the window object?

Looking at the jQuery code I see this -

( function( global, factory ) {

"use strict";

if ( typeof module === "object" && typeof module.exports === "object" ) {

    // For CommonJS and CommonJS-like environments where a proper `window`
    // is present, execute the factory and get jQuery.
    // For environments that do not have a `window` with a `document`
    // (such as Node.js), expose a factory as module.exports.
    // This accentuates the need for the creation of a real `window`.
    // e.g. var jQuery = require("jquery")(window);
    // See ticket #14549 for more info.
    module.exports = global.document ?
        factory( global, true ) :
        function( w ) {
            if ( !w.document ) {
                throw new Error( "jQuery requires a window with a document" );
            }
            return factory( w );
        };
} else {
    factory( global );
}

// Pass this if window is not defined yet
} )( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {

So without access to window or document, it can't work?

0

There are 0 best solutions below