Need a method to replace ajax.googleapis.com references with China-friendly CDN within Moodle plugins

Need a method to replace ajax.googleapis.com references with China-friendly CDN within Moodle plugins

by Matthew Willis -
Number of replies: 3

Hi there!

I've recently taken on the support of a China-hosted Moodle 3.3 site, which is currently suffering long load times due to the Great Firewall of China blocking connections to Google domains (in this case, ajax.googleapis.com). I live in Australia, and therefore cannot replicate the performance issues here, but can with remote VMs). I've checked the Moodle source code on the server, and there is nothing there that I can see that refers to "*.googleapis.com" within the PHP code anywhere; which leads me to assume that a plugin, of which there are many installed on the site, that is incorrectly calling the API from ajax.googleapi.com on each page load. The catch is that I have no idea which plugin could be doing this, and there are many installed on the server. 

Is there an easy way to search the source code for all plugins easily, or am I forced to check the source code on GitHub and the like?

Average of ratings: -
In reply to Matthew Willis

Re: Need a method to replace ajax.googleapis.com references with China-friendly CDN within Moodle plugins

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

I would do this from the browser console. As in this screenshot ...


Average of ratings: Useful (1)
In reply to Justin Hunt

Re: Need a method to replace ajax.googleapis.com references with China-friendly CDN within Moodle plugins

by Matthew Willis -

Hi Justin,

Thanks for this. Unfortunately, Chrome and Firefox (Windows OS) natively lack the functionality to download the source files from the Developer Tools window. Fortunately, there is a Chrome plugin that enables exactly that. Unfortunately, I don't know if the Developer tools within the browser allow me to view the PHP code that is responsible for injecting the troublesome script to the index.html page. I'll scour through the many files now available and return here with my results.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

In reply to Matthew Willis

Re: Need a method to replace ajax.googleapis.com references with China-friendly CDN within Moodle plugins

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

What you see in the browser is front end , and the PHP is backend. You will not be able to download any PHP files using a browser tool. 

My suggestion was really for tracking down where the calls to googleapis are coming from from the browser. You can often tell from the surrounding source. When I looked at the code here on Moodle.org, its coming from the theme. 

Really the best way though is what you were doing. Search the source tree for your Moodle site. Most IDEs have that feature. I am sure its possible with command line tools and other things too. When I did that using PHP Storm I got lots of hits from the lib/google directory. And from the Google Docs repository. That means you would need to find out which services are using the Google APIs and turn them off if possible.