Since webassets will not work in GAE to compress js / css on the fly, it seems that it is best to do this when deploying.
After many searches, I came up with the script below to achieve this.
At first, I thought it was best to leave the javascript path in base.html as it is, and just compress css / js.
cssmin compresses css and overwrites the original. However, closing does not allow overwriting the original, and this concept has already been completed.
The second problem is that even if I have a closure overwriting the original file, caching will be a problem. For this reason, each deployment of mini css / js must be accompanied by a random number in the file name, so that new versions are actually collected after the new deployment. With the concept that I came up with, it will be impossible.
Therefore, the only way to achieve this is to change base.html to sed or something else.
Before reinventing the wheel, is there a better way to do this? Thank you very much
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)
source share