@@ -142,7 +142,7 @@ fn clearList(_: *const ScriptManager, list: *OrderList) void {
142142 std .debug .assert (list .first == null );
143143}
144144
145- pub fn addFromElement (self : * ScriptManager , element : * parser.Element ) ! void {
145+ pub fn addFromElement (self : * ScriptManager , element : * parser.Element , comptime ctx : [] const u8 ) ! void {
146146 if (try parser .elementGetAttribute (element , "nomodule" ) != null ) {
147147 // these scripts should only be loaded if we don't support modules
148148 // but since we do support modules, we can just skip them.
@@ -230,7 +230,11 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
230230 self .scripts .append (& pending_script .node );
231231 return ;
232232 } else {
233- log .debug (.http , "script queue" , .{ .url = remote_url .? });
233+ log .debug (.http , "script queue" , .{
234+ .ctx = ctx ,
235+ .url = remote_url .? ,
236+ .stack = page .js .stackTrace () catch "???" ,
237+ });
234238 }
235239
236240 pending_script .getList ().append (& pending_script .node );
@@ -255,40 +259,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
255259 });
256260}
257261
258- // @TODO: Improving this would have the simplest biggest performance improvement
259- // for most sites.
260- //
261- // For JS imports (both static and dynamic), we currently block to get the
262- // result (the content of the file).
263- //
264- // For static imports, this is necessary, since v8 is expecting the compiled module
265- // as part of the function return. (we should try to pre-load the JavaScript
266- // source via module.GetModuleRequests(), but that's for a later time).
267- //
268- // For dynamic dynamic imports, this is not strictly necessary since the v8
269- // call returns a Promise; we could make this a normal get call, associated with
270- // the promise, and when done, resolve the promise.
271- //
272- // In both cases, for now at least, we just issue a "blocking" request. We block
273- // by ticking the http client until the script is complete.
274- //
275- // This uses the client.blockingRequest call which has a dedicated handle for
276- // these blocking requests. Because they are blocking, we're guaranteed to have
277- // only 1 at a time, thus the 1 reserved handle.
278- //
279- // You almost don't need the http client's blocking handle. In most cases, you
280- // should always have 1 free handle whenever you get here, because we always
281- // release the handle before executing the doneCallback. So, if a module does:
282- // import * as x from 'blah'
283- // And we need to load 'blah', there should always be 1 free handle - the handle
284- // of the http GET we just completed before executing the module.
285- // The exception to this, and the reason we need a special blocking handle, is
286- // for inline modules within the HTML page itself:
287- // <script type=module>import ....</script>
288- // Unlike external modules which can only ever be executed after releasing an
289- // http handle, these are executed without there necessarily being a free handle.
290- // Thus, Http/Client.zig maintains a dedicated handle for these calls.
291- pub fn getModule (self : * ScriptManager , url : [:0 ]const u8 ) ! void {
262+ pub fn getModule (self : * ScriptManager , url : [:0 ]const u8 , referrer : []const u8 ) ! void {
292263 const gop = try self .sync_modules .getOrPut (self .allocator , url );
293264 if (gop .found_existing ) {
294265 // already requested
@@ -305,6 +276,13 @@ pub fn getModule(self: *ScriptManager, url: [:0]const u8) !void {
305276 var headers = try self .client .newHeaders ();
306277 try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
307278
279+ log .debug (.http , "script queue" , .{
280+ .url = url ,
281+ .ctx = "module" ,
282+ .referrer = referrer ,
283+ .stack = self .page .js .stackTrace () catch "???" ,
284+ });
285+
308286 try self .client .request (.{
309287 .url = url ,
310288 .ctx = sync ,
@@ -355,7 +333,7 @@ pub fn waitForModule(self: *ScriptManager, url: [:0]const u8) !GetResult {
355333 }
356334}
357335
358- pub fn getAsyncModule (self : * ScriptManager , url : [:0 ]const u8 , cb : AsyncModule.Callback , cb_data : * anyopaque ) ! void {
336+ pub fn getAsyncModule (self : * ScriptManager , url : [:0 ]const u8 , cb : AsyncModule.Callback , cb_data : * anyopaque , referrer : [] const u8 ) ! void {
359337 const async = try self .async_module_pool .create ();
360338 errdefer self .async_module_pool .destroy (async );
361339
@@ -368,6 +346,13 @@ pub fn getAsyncModule(self: *ScriptManager, url: [:0]const u8, cb: AsyncModule.C
368346 var headers = try self .client .newHeaders ();
369347 try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
370348
349+ log .debug (.http , "script queue" , .{
350+ .url = url ,
351+ .ctx = "dynamic module" ,
352+ .referrer = referrer ,
353+ .stack = self .page .js .stackTrace () catch "???" ,
354+ });
355+
371356 try self .client .request (.{
372357 .url = url ,
373358 .method = .GET ,
0 commit comments