Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support dns-prefetch #535

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions webf/lib/src/html/head.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) 2019-2022 The Kraken authors. All rights reserved.
* Copyright (C) 2022-present The WebF authors. All rights reserved.
*/
import 'dart:io';

import 'package:flutter/scheduler.dart';
import 'package:webf/css.dart';
Expand Down Expand Up @@ -29,6 +30,7 @@ class HeadElement extends Element {
}

const String _REL_STYLESHEET = 'stylesheet';
const String DNS_PREFETCH = 'dns-prefetch';

// https://www.w3.org/TR/2011/WD-html5-author-20110809/the-link-element.html#the-link-element
class LinkElement extends Element {
Expand Down Expand Up @@ -98,13 +100,18 @@ class LinkElement extends Element {
set type(String value) {
internalSetAttribute('type', value);
}

void _resolveHyperlink() {
Future<void> _resolveHyperlink() async {
String? href = getAttribute('href');
String? rel = getAttribute('rel');
if (href != null) {
String base = ownerDocument.controller.url;
try {
_resolvedHyperlink = ownerDocument.controller.uriParser!.resolve(Uri.parse(base), Uri.parse(href));
Uri hrefUri = Uri.parse(href);
if (rel != null && rel == DNS_PREFETCH) {
await InternetAddress.lookup(hrefUri.host);
}

_resolvedHyperlink = ownerDocument.controller.uriParser!.resolve(Uri.parse(base), hrefUri);
} catch (_) {
// Ignoring the failure of resolving, but to remove the resolved hyperlink.
_resolvedHyperlink = null;
Expand Down
Loading