Minify JS template tag

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from django import template
from jsmin import jsmin

register = template.Library()

class MinifyJs(template.Node):
    def __init__(self, nodelist):
        self.nodelist = nodelist
    def render(self, context):
        return jsmin(self.nodelist.render(context))

def minifyjs(parser, token):
    nodelist = parser.parse(('endminifyjs',))
    parser.delete_first_token()
    return MinifyJs(nodelist)

minifyjs = register.tag(minifyjs)

More like this

  1. Django Template "include_raw" tag by wwu.housing 4 years, 8 months ago
  2. Template tags to integrate with modconcat by matthanger 4 years, 9 months ago
  3. Template tag for compressed CSS & JS (GAE version) by jeffar 5 years, 9 months ago
  4. A dict template tag by Batiste 5 years, 12 months ago
  5. Templatetag for JS merging and compression by msaelices 6 years, 7 months ago

Comments

(Forgotten your password?)