@@ -131,7 +131,7 @@ fn clearList(_: *const ScriptManager, list: *OrderList) void {
131131 std .debug .assert (list .first == null );
132132}
133133
134- pub fn addFromElement (self : * ScriptManager , element : * parser.Element ) ! void {
134+ pub fn addFromElement (self : * ScriptManager , element : * parser.Element , comptime ctx : [] const u8 ) ! void {
135135 if (try parser .elementGetAttribute (element , "nomodule" ) != null ) {
136136 // these scripts should only be loaded if we don't support modules
137137 // but since we do support modules, we can just skip them.
@@ -219,7 +219,11 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
219219 self .scripts .append (& pending_script .node );
220220 return ;
221221 } else {
222- log .debug (.http , "script queue" , .{ .url = remote_url .? });
222+ log .debug (.http , "script queue" , .{
223+ .ctx = ctx ,
224+ .url = remote_url .? ,
225+ .stack = page .js .stackTrace () catch "???" ,
226+ });
223227 }
224228
225229 pending_script .getList ().append (& pending_script .node );
@@ -244,40 +248,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
244248 });
245249}
246250
247- // @TODO: Improving this would have the simplest biggest performance improvement
248- // for most sites.
249- //
250- // For JS imports (both static and dynamic), we currently block to get the
251- // result (the content of the file).
252- //
253- // For static imports, this is necessary, since v8 is expecting the compiled module
254- // as part of the function return. (we should try to pre-load the JavaScript
255- // source via module.GetModuleRequests(), but that's for a later time).
256- //
257- // For dynamic dynamic imports, this is not strictly necessary since the v8
258- // call returns a Promise; we could make this a normal get call, associated with
259- // the promise, and when done, resolve the promise.
260- //
261- // In both cases, for now at least, we just issue a "blocking" request. We block
262- // by ticking the http client until the script is complete.
263- //
264- // This uses the client.blockingRequest call which has a dedicated handle for
265- // these blocking requests. Because they are blocking, we're guaranteed to have
266- // only 1 at a time, thus the 1 reserved handle.
267- //
268- // You almost don't need the http client's blocking handle. In most cases, you
269- // should always have 1 free handle whenever you get here, because we always
270- // release the handle before executing the doneCallback. So, if a module does:
271- // import * as x from 'blah'
272- // And we need to load 'blah', there should always be 1 free handle - the handle
273- // of the http GET we just completed before executing the module.
274- // The exception to this, and the reason we need a special blocking handle, is
275- // for inline modules within the HTML page itself:
276- // <script type=module>import ....</script>
277- // Unlike external modules which can only ever be executed after releasing an
278- // http handle, these are executed without there necessarily being a free handle.
279- // Thus, Http/Client.zig maintains a dedicated handle for these calls.
280- pub fn getModule (self : * ScriptManager , url : [:0 ]const u8 ) ! void {
251+ pub fn getModule (self : * ScriptManager , url : [:0 ]const u8 , referrer : []const u8 ) ! void {
281252 const gop = try self .sync_modules .getOrPut (self .allocator , url );
282253 if (gop .found_existing ) {
283254 // already requested
@@ -294,6 +265,13 @@ pub fn getModule(self: *ScriptManager, url: [:0]const u8) !void {
294265 var headers = try self .client .newHeaders ();
295266 try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
296267
268+ log .debug (.http , "script queue" , .{
269+ .url = url ,
270+ .ctx = "module" ,
271+ .referrer = referrer ,
272+ .stack = self .page .js .stackTrace () catch "???" ,
273+ });
274+
297275 try self .client .request (.{
298276 .url = url ,
299277 .ctx = sync ,
@@ -340,7 +318,7 @@ pub fn waitForModule(self: *ScriptManager, url: [:0]const u8) !GetResult {
340318 }
341319}
342320
343- pub fn getAsyncModule (self : * ScriptManager , url : [:0 ]const u8 , cb : AsyncModule.Callback , cb_data : * anyopaque ) ! void {
321+ pub fn getAsyncModule (self : * ScriptManager , url : [:0 ]const u8 , cb : AsyncModule.Callback , cb_data : * anyopaque , referrer : [] const u8 ) ! void {
344322 const async = try self .async_module_pool .create ();
345323 errdefer self .async_module_pool .destroy (async );
346324
@@ -353,6 +331,13 @@ pub fn getAsyncModule(self: *ScriptManager, url: [:0]const u8, cb: AsyncModule.C
353331 var headers = try self .client .newHeaders ();
354332 try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
355333
334+ log .debug (.http , "script queue" , .{
335+ .url = url ,
336+ .ctx = "dynamic module" ,
337+ .referrer = referrer ,
338+ .stack = self .page .js .stackTrace () catch "???" ,
339+ });
340+
356341 try self .client .request (.{
357342 .url = url ,
358343 .method = .GET ,
0 commit comments