title: How can I make Google's closure library load faster?
body: <p>I'm writing a simple phone number parser based on [<a href="http://code.google.com/p/libphonenumber/" rel="nofollow">libphonenumber</a>]. Unfortunately, "http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js" takes forever to load, and when I wget the file and just include it as src="base.js", a bunch of errors pop up.</p>
  
  <p>My guess is that this is because the library has not yet loaded yet, so the goog.require() statements are failing.</p>
  
  <p>What can I do?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Phone Number Parser&lt;/title&gt;
  &lt;script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    goog.require('goog.dom');
    goog.require('goog.json');
    goog.require('goog.proto2.ObjectSerializer');
    goog.require('goog.string.StringBuffer');
  &lt;/script&gt;
  &lt;script src="phonemetadata.pb.js"&gt;&lt;/script&gt;
  &lt;script src="phonenumber.pb.js"&gt;&lt;/script&gt;
  &lt;script src="metadata.js"&gt;&lt;/script&gt;
  &lt;script src="phonenumberutil.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
  numbers = ['6509066389', '+40723875777', '720-935-6433', '914-262-7178', '7123040634'];
  for (i in numbers) {
      console.log(format_for_five9(numbers[i]));
  }
  
  function format_for_five9(phoneNumber) {
    var $ = goog.dom.getElement;
    var regionCode = 'US'; 
    var output = new goog.string.StringBuffer();
    try {
      var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance();
      var number = phoneUtil.parseAndKeepRawInput(phoneNumber, regionCode);
  
      number_json_serial = goog.json.serialize(new goog.proto2.ObjectSerializer(goog.proto2.ObjectSerializer.KeyOption.NAME).serialize(number));
      number_json = goog.json.parse(number_json_serial);
  
      if(phoneUtil.isValidNumberForRegion(number, regionCode)) {
          five9_format = number_json.national_number.toString();
      }
      else {
          five9_format = number_json.country_code.toString() + number_json.national_number.toString();
      }
    } catch (e) {
      output.append('\n' + e);
      console.log(e);
    }
    return five9_format;
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>