How to set up localhost to redirect a website

I am asking this question from an awkward situation. As you may know or not know, Google is blocked in China. A discouraging consequence (at least to me) is that visiting Stack Exchange sites, like Stack Overflow where I used to be very active while I was doing my degree in UK, is very hard. It can take more than 20s to load a page. The problem is that Stack Exchange sites rely on an external JAVA script from

http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js

but since Google is blocked, this script can't be accessed. But Firefox would spend considerable time trying to get this script. (Note that the jquery version may change in future, but it is 1.12.4 when this question is asked. Use F12 to check the most up-to-date version.)

In fact, this script can be accessed freely from

https://code.jquery.com/jquery-1.12.4.min.js

So, an ideal solution is to redirect the page under Google domain to Jquery domain.

Is this possible by modifying /etc/hosts files? At the moment I am simply doing a brutal webpage blocking:

127.0.0.1    ajax.googleapis.com

Although Firefox now will stop trying to load this script so visiting stack exchange sites becomes as fast as normal, many site features are not useable, like voting etc. So the best solution is a redirection.


If immediate redirection is impossible, then I guess I need to download the JAVA script from Jquery to my laptop, then redirect the googleapis page to my localhost. However, I don't know how to set up a localhost, especially where to place my downloaded script.

Can anyone help me out? Very appreciated.


Solution 1:

Basically, besides the hosts file redirection you already figured out, your computer needs to provide the web service. So that means installing a web server which would allow your browser to find the javascript at https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js

The difference is ajax.googleapis.com resolves to 127.0.0.1 so your web server must/will deliver jquery.min.js to your browser instead of Google's server. Installing a server may or may not be as hard as you might think. It just depends on your experience and how eager you are to read documentation (man pages, web hosted, etc.) for the web server you choose. Apache2 is the current "full service" (does everything) free web server, but you may want to search for a light weight alternative.

I hope this helps and gets you going and looking in the right direction. The best part of doing it this way is you aren't stretching any boundaries with the authorities.

By the way, https resolves to port 443 on your configuration (http is port 80). This is the secure transport configuration.