Commit e78ac402 authored by Romain Courteaud's avatar Romain Courteaud

Speed up getAbsoluteURL

Do not create a DOM document to calculate an URL.
parent beb63634
...@@ -67,7 +67,8 @@ module.exports = function (grunt) { ...@@ -67,7 +67,8 @@ module.exports = function (grunt) {
'FileReader', 'FileReader',
'Node', 'Node',
'navigator', 'navigator',
'Event' 'Event',
'URL'
] ]
} }
}, },
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* http://www.renderjs.org/documentation * http://www.renderjs.org/documentation
*/ */
(function (document, window, RSVP, DOMParser, Channel, MutationObserver, (function (document, window, RSVP, DOMParser, Channel, MutationObserver,
Node, FileReader, Blob, navigator, Event) { Node, FileReader, Blob, navigator, Event, URL) {
"use strict"; "use strict";
function readBlobAsDataURL(blob) { function readBlobAsDataURL(blob) {
...@@ -1087,18 +1087,8 @@ ...@@ -1087,18 +1087,8 @@
// renderJS.getAbsoluteURL // renderJS.getAbsoluteURL
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
renderJS.getAbsoluteURL = function (url, base_url) { renderJS.getAbsoluteURL = function (url, base_url) {
var doc, base, link, if (base_url && url) {
html = "<!doctype><html><head></head></html>"; return new URL(url, base_url).href;
if (url && base_url && !isAbsoluteOrDataURL.test(url)) {
doc = (new DOMParser()).parseFromString(html, 'text/html');
base = doc.createElement('base');
link = doc.createElement('link');
doc.head.appendChild(base);
doc.head.appendChild(link);
base.href = base_url;
link.href = url;
return link.href;
} }
return url; return url;
}; };
...@@ -1682,4 +1672,4 @@ ...@@ -1682,4 +1672,4 @@
bootstrap(); bootstrap();
}(document, window, RSVP, DOMParser, Channel, MutationObserver, Node, }(document, window, RSVP, DOMParser, Channel, MutationObserver, Node,
FileReader, Blob, navigator, Event)); FileReader, Blob, navigator, Event, URL));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment