Search code examples
javascripthtmlgoogle-mapsgoogle-analyticsgoogle-custom-search

Possible to load multiple Google scripts in one file


I was just wondering if anyone knew how - or if it's even possible - to load multiple Google scripts in one file? See because on some of my pages I'm loading up to three or more Google scripts:

  1. Google Analytics
  2. Google CSE
  3. Google Maps
  4. (once in a while) Google Webfonts

Trying to cut back on HTTP requests and would like to be able to load something like google.js that included all of that.


Solution

  • You can't download combined js files from Google as a single http request, but you can download, combine and load them your own website provided you update them often enough (like with a cron job twice a day for example). You can even set caching headers if you wish.

    Despite all that I would advice against doing it - just load those scripts asynchronously (but from within html, not separate file) - it's non-blocking and will not slow down rendering start of your website.