Since webassets won't work on GAE to compress a js/css on the fly, it seems the best approach is to do it upon deployment.
After a lot of googling I came up with the script below to achieve this.
At first I thought the best would be to leave the javascript path in base.html
as it is and simply compress the css/js.
cssmin compresses the css and overwrites the original. However closure doesn't allow overwriting the original and this concept fails already.
The second problem is, even if I got closure overwriting the original file, caching will be a problem. For this reason each deployment of minified css/js should come with a random number in file name, so that the new versions are actually picked up after a new deployment. With the concept I came up with, this won't be possible though.
Hence the only way to achieve this would be modifying the base.html
with sed
or something.
Before I reinvent the wheel, is there a better approach to do this? Many thanks
import sys, os
import cssmin
def main():
if len(sys.argv) == 1:
return
appId = sys.argv[1]
print "appId", appId
cmd = r'java -jar compiler.jar --js=/src/application/static/f11/f11.js --js_output_file=/src/application/static/f11/f11.min.js'
os.system(cmd)
output = cssmin.cssmin(open('/src/application/static/f11/f11.css').read())
f = open('/src/application/static/f11/f11.css','w')
f.write(output)
# Perform appcfg.py to update GAE server
cmd = r'"\google_appengine\appcfg.py"'
os.system(cmd + " update . " + " -A %s"%appId)
if __name__ == "__main__":
main()