📜 ⬆️ ⬇️

No cdn one

Recently, it has become fashionable to talk about accessibility when developing websites, write rel, alt, make a version for the visually impaired, and so on, but why not think about normal users first. Connecting jQuery from CDN:

<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script> 

... many people forget a very important detail.

Of course, you need to remember to check whether the library has loaded, and if not, then download from your own site. To do this, you can simply add:

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script> 

It is so simple, however, many large sites sin by forgetting about it. A real example is a large resource tied to working with clients from China, forgetting about this check, made it impossible for these clients to work with their website if the client did not use vpn. The reason is simple: Google loaded with CDN, and in China almost all Google is blocked (被 和谐 了).
')
Developers, please do not forget about it!

Well, those who do not want to mess with vpn, and at the same time want the ajax.googleapis.com scripts to load, we can recommend the following advice:
List the following in the hosts file
 127.0.0.1 ajax.googleapis.com 

Then install python, if it is not already installed on the system, and run the script:
 #-*- coding: utf-8 -*- import SocketServer import SimpleHTTPServer import urllib import os PORT = 80 class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): if '/ajax/libs/' in self.path: self.path = self.path.replace('/ajax/libs/','http://yastatic.net/') self.copyfile(urllib.urlopen(self.path), self.wfile) if os.name == 'posix': httpd = SocketServer.ForkingTCPServer(('', PORT), Proxy) else: httpd = SocketServer.ThreadingTCPServer(('', PORT), Proxy) print "serving at port", PORT httpd.serve_forever() 

In this case, of course, you need to make sure that the scripts from yastatic.net are loaded.

Source: https://habr.com/ru/post/250663/


All Articles