combine javascript files at deployment in python

后端 未结 6 2123
一向
一向 2021-01-30 07:41

I\'m trying to reduce the number of scripts included in our website and we use buildout to handle deployments. Has anybody successfully implemented a method of combining and com

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 08:26

    A slightly different take on the solution proposed by Rushabh. Rather than a file based compress function, this is string based and somewhat simpler:

    def jsmerge(file_names, debug=False):
    """combines several js files together, with optional minification"""
    js = ""
    for file_name in file_names:
        js += open(file_name).read()
    
    # if debug is enabled, we skip the minification
    if debug:
        return js
    else:
        return jsmin(js)
    

提交回复
热议问题