Skip to content

Commit dfdaff8

Browse files
committed
Load time improvements (fixes #140):
- move hash to a query parameter (it works!) - do widget request later, let app render/loading in case the request is fast enough. [email protected] Review URL: https://codereview.chromium.org/1131933003
1 parent aba85e3 commit dfdaff8

File tree

5 files changed

+1201
-1080
lines changed

5 files changed

+1201
-1080
lines changed

pkg/dev_compiler/lib/devc.dart

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,16 @@ class CompilerServer {
290290
if (isEntryPage) compiler._runAgain();
291291

292292
// To help browsers cache resources that don't change, we serve these
293-
// resources under a path containing their hash:
294-
// /cached/{hash}/{path-to-file.js}
295-
bool isCached = segments.length > 1 && segments[0] == 'cached';
296-
if (isCached) {
297-
// Changing the request lets us record that the hash prefix is handled
298-
// here, and that the underlying handler should use the rest of the url to
299-
// determine where to find the resource in the file system.
300-
request = request.change(path: path.join('cached', segments[1]));
301-
}
293+
// resources by adding a query parameter containing their hash:
294+
// /{path-to-file.js}?____cached={hash}
295+
var hash = request.url.queryParameters['____cached'];
302296
var response = handler(request);
303-
var policy = isCached ? 'max-age=${24 * 60 * 60}' : 'no-cache';
297+
var policy = hash != null ? 'max-age=${24 * 60 * 60}' : 'no-cache';
304298
var headers = {'cache-control': policy};
305-
if (isCached) {
299+
if (hash != null) {
306300
// Note: the cache-control header should be enough, but this doesn't hurt
307301
// and can help renew the policy after it expires.
308-
headers['ETag'] = segments[1];
302+
headers['ETag'] = hash;
309303
}
310304
return response.change(headers: headers);
311305
};

pkg/dev_compiler/lib/runtime/messages_widget.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import 'package:path/path.dart' as path;
1515
import 'package:source_span/source_span.dart';
1616
import 'package:dev_compiler/src/summary.dart';
1717

18-
main() async => displayMessages(await HttpRequest.getString('messages.json'));
18+
main() async {
19+
await window.animationFrame;
20+
displayMessages(await HttpRequest.getString('messages.json'));
21+
}
1922

2023
void displayMessages(String data) {
2124
var summary = GlobalSummary.parse(JSON.decode(data));

0 commit comments

Comments
 (0)