Skip to content
Browse files

gallery-2010.04.21-21-51 spartanp gallery-speedns

  • Loading branch information...
1 parent c2e1068 commit eaf3b43f9048130d5c7c690d48c1c3c435969098 YUI Builder committed
Showing with 89 additions and 0 deletions.
  1. +24 −0 src/gallery-speedns/build.properties
  2. +6 −0 src/gallery-speedns/build.xml
  3. +59 −0 src/gallery-speedns/js/speedns.js
View
24 src/gallery-speedns/build.properties
@@ -0,0 +1,24 @@
+# Speed DNS Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=gallery-speedns
+
+# The list of files which should be concatenated to create the component.
+# NOTE: For a css component (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+component.jsfiles=speedns.js
+
+# The list of modules this component requires. Used to setup the Y.add module call for YUI 3.
+# NOTE: For a css component, this property is not used/required.
+
+# component.use, component.supersedes, component.optional and component.skinnable are other properties which can be defined
+component.requires=get, event-custom
+
+
View
6 src/gallery-speedns/build.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Speed DNS" default="local">
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml"
+ description="Default Build Properties and Targets" />
+</project>
View
59 src/gallery-speedns/js/speedns.js
@@ -0,0 +1,59 @@
+/**
+ * Static class that holds all the utility functions.
+ */
+var SpeedNS = {
+
+ /**
+ * Regular expression to match a domain name from uri.
+ */
+ domainRegex: /((http)|(https)):\/\/[A-Za-z0-9.\-]+\//,
+
+ /**
+ * Fires DNS lookups for all the links in the current document.
+ *
+ * @param {object} e is the current html document for which the onload event
+ * has fired.
+ */
+ prefetch: function() {
+ var doc = document,
+ links = doc.getElementsByTagName("a");
+ var uniqueLinks = {}, i, l;
+ for (i = 0, l = links.length; i < l; i++ ) {
+ var uri = links[i].href,
+ matches = SpeedNS.domainRegex.exec(uri),
+ domain = matches[0];
+
+ // hash each domain name.
+ uniqueLinks[domain] = false;
+ }
+
+ for (var ud in uniqueLinks) {
+ /**
+ * We do it only if its a property that is created on object, because
+ * some libraries like prototype can screw this up.
+ */
+ if (uniqueLinks.hasOwnProperty(ud)) {
+ SpeedNS.prefetchDNSForDomain(ud,
+ SpeedNS.processHeadResponses);
+ }
+ }
+ },
+
+ /**
+ * Prefetches DNS for the domain using hidden image technique. Uses the
+ * favicon image as source.
+ *
+ * @param {String} domain is the domain for which the DNS should be
+ * prefetched.
+ */
+ prefetchDNSForDomain: function(domain) {
+ // some browsers do not support image object, so check if it does.
+ if (document.images) {
+ var i = new Image(16, 16);
+ i.src = domain + "favicon.ico";
+ }
+ }
+};
+
+// Alias it on YUI instance.
+Y.speedns = SpeedNS;

0 comments on commit eaf3b43

Please sign in to comment.
Something went wrong with that request. Please try again.