cachebust

Copyright (c) 2015 Timothy Savannah under LGPLv2. You should have received a copy of this as LICENSE with this distribution.
 
"cachebust" provides a means to ensure that browsers always fetch updated files when they change, by adding a param 'cachebust=$md5sum' to all the asset tags. When the file changes, the md5sum is updated, and the browser makes a new request.

 
Package Contents
       

 
Functions
       
cachebustFile(filename, encoding='utf-8', assetRoot=None, quiet=False)
cachebustFile - cachebusts provided file and returns the cachebusted html.
 
@param html <str> - String of html
@param encoding <str> - Encoding to use (default, utf-8)
@param assetRoot <None/str> - Filesystem path which should be treated as representing "/" for urls. If None is provided, current directory will be used.
@param quiet <bool> - True to silence warnings to stderr when cachebusting cannot be applied.
 
@return - cachebusted HTML
cachebustHtml(html, encoding='utf-8', assetRoot=None, quiet=False)
cachebustHtml - cachebusts provided html string and returns the cachebusted html.
 
@param html <str> - String of html
@param encoding <str> - Encoding to use (default, utf-8)
@param assetRoot <None/str> - Filesystem path which should be treated as representing "/" for urls. If None is provided, current directory will be used.
@param quiet <bool> - True to silence warnings to stderr when cachebusting cannot be applied.
 
@return - cachebusted HTML
cachebustUrl(urlValue, assetRoot=None, quiet=False)
cachebustUrl - Uses a parameter, "cachebust" to ensure browser caching always picks up new value. Returns a cachebusted url from a given asset url
 
@param urlValue <str> - Url value of asset (like value of "src" attribute)
@param assetRoot <None/str> - Filesystem path which should be treated as representing "/" for urls. If None is provided, current directory will be used.
@param quiet <bool> - True to silence warnings to stderr when cachebusting cannot be applied.
 
@return - The same url on error, otherwise the url with "cachebust" param set to md5sum of file (so changes cause a refresh)
md5 = openssl_md5(...)
Returns a md5 hash object; optionally initialized with a string
updateDocument(parserObj, assetRoot=None, quiet=False)
updateDocument - Updates an AdvancedHTMLParser.AdvancedHTMLParser object to cachebust all items
 
@param parserObj <AdvancedHTMLParser.AdvancedHTMLParser> - The object which represents the document to cachebust
@param assetRoot <None/str> - Filesystem path which should be treated as representing "/" for urls. If None is provided, current directory will be used.
@param quiet <bool> - True to silence warnings to stderr when cachebusting cannot be applied.
 
@return - None
updateTag(tagObj, fieldName=None, assetRoot=None, quiet=False)
updateTag - Updates an AdvancedHTMLParser.AdvancedTag object to cachebust its source.
 
 
@param tagObj <AdvancedHTMLParser.AdvancedTag> - A tag which will be cachebusted
@param fieldName <str/None> - The attribute to cachebust. If "None" is provided, based on the tag name one will be picked ("src" for img,script and "rel" for link)
@param assetRoot <None/str> - Filesystem path which should be treated as representing "/" for urls. If None is provided, current directory will be used.
@param quiet <bool> - True to silence warnings to stderr when cachebusting cannot be applied.
 
@return - True on success (tag was updated), False on failure (tag was not updated)