Skip to content

Instantly share code, notes, and snippets.

@richarvey
Created April 21, 2014 22:21
Show Gist options
  • Save richarvey/11158596 to your computer and use it in GitHub Desktop.
Save richarvey/11158596 to your computer and use it in GitHub Desktop.
cache-tester
#!/usr/bin/python
import urllib2, httplib, sys
from BeautifulSoup import BeautifulSoup
site = "<YOUR URL>"
page = urllib2.urlopen('http://' + site)
soup = BeautifulSoup(page)
tags=soup.findAll('img')
print "\nChecking Images"
print "===============\n"
for tag in tags:
asset = tag['src']
connection = httplib.HTTPConnection(site)
connection.request("HEAD", asset)
response = connection.getresponse()
cachecontrol = response.getheader('cache-control')
print '%100s : %20s' % (asset, cachecontrol)
tags=soup.findAll('link')
print "\nChecking CSS"
print "===============\n"
for tag in tags:
if "css" in tag['href'] or "CSS" in tag['href']:
asset = tag['href']
connection = httplib.HTTPConnection(site)
connection.request("HEAD", asset)
response = connection.getresponse()
print '%100s : %20s' % (asset, cachecontrol)
tags=soup.findAll('script')
print "\nChecking JS"
print "===============\n"
for tag in tags:
try:
asset = tag['src']
except:
print "%100s" % ("Skipping asset")
else:
connection = httplib.HTTPConnection(site)
connection.request("HEAD", asset)
response = connection.getresponse()
print '%100s : %20s' % (asset, cachecontrol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment