@@ -131,7 +131,7 @@ fn clearList(_: *const ScriptManager, list: *OrderList) void {
131
131
std .debug .assert (list .first == null );
132
132
}
133
133
134
- pub fn addFromElement (self : * ScriptManager , element : * parser.Element ) ! void {
134
+ pub fn addFromElement (self : * ScriptManager , element : * parser.Element , comptime ctx : [] const u8 ) ! void {
135
135
if (try parser .elementGetAttribute (element , "nomodule" ) != null ) {
136
136
// these scripts should only be loaded if we don't support modules
137
137
// but since we do support modules, we can just skip them.
@@ -219,7 +219,11 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
219
219
self .scripts .append (& pending_script .node );
220
220
return ;
221
221
} 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
+ });
223
227
}
224
228
225
229
pending_script .getList ().append (& pending_script .node );
@@ -244,40 +248,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
244
248
});
245
249
}
246
250
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 {
281
252
const gop = try self .sync_modules .getOrPut (self .allocator , url );
282
253
if (gop .found_existing ) {
283
254
// already requested
@@ -294,6 +265,13 @@ pub fn getModule(self: *ScriptManager, url: [:0]const u8) !void {
294
265
var headers = try self .client .newHeaders ();
295
266
try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
296
267
268
+ log .debug (.http , "script queue" , .{
269
+ .url = url ,
270
+ .ctx = "module" ,
271
+ .referrer = referrer ,
272
+ .stack = self .page .js .stackTrace () catch "???" ,
273
+ });
274
+
297
275
try self .client .request (.{
298
276
.url = url ,
299
277
.ctx = sync ,
@@ -340,7 +318,7 @@ pub fn waitForModule(self: *ScriptManager, url: [:0]const u8) !GetResult {
340
318
}
341
319
}
342
320
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 {
344
322
const async = try self .async_module_pool .create ();
345
323
errdefer self .async_module_pool .destroy (async );
346
324
@@ -353,6 +331,13 @@ pub fn getAsyncModule(self: *ScriptManager, url: [:0]const u8, cb: AsyncModule.C
353
331
var headers = try self .client .newHeaders ();
354
332
try self .page .requestCookie (.{}).headersForRequest (self .page .arena , url , & headers );
355
333
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
+
356
341
try self .client .request (.{
357
342
.url = url ,
358
343
.method = .GET ,
0 commit comments