django-htmlmin icon indicating copy to clipboard operation
django-htmlmin copied to clipboard

Minify inline JavaScript

Open fsouza opened this issue 13 years ago • 5 comments

It'd be nice to minify inline JavaScript.

The minify function could receive a boolean parameter (just like ignore_comments):

minify(html_code, compress_js =True)
minify(html_code, compress_js=False)

fsouza avatar May 21 '11 21:05 fsouza

Hi @fsouza , can we minimize javascript in this now......

paritosh90 avatar May 24 '12 13:05 paritosh90

Hi @paritosh90, i think that it is ideal to use tools like django-compressor, that minifies and group JavaScript files.

So, the code below:

{% compress js %}
<script src="myfile.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
    alert("bla bla");
});
</script>
{% endcompress %}

would generate one javascript file with the contents compressed, and change the entire compress block to a <script src="file.js"></script> tag.

fsouza avatar May 24 '12 13:05 fsouza

@fsouza you are right about django-compress but here we are assigning name to some javascript variables in django template like /////////////////////////////////////////////////////

//////////////////////////////////////////////////// here we cannot use django-compress, because it combine all js into one when server restarts. I think if we implement this feature in django-htmlmini this will be the best app to be used for minifying client side code and its combination with django-compress will do all of the job one needs for minifying in django. Anyways this app is quite cool

Thanks

paritosh90 avatar May 24 '12 14:05 paritosh90

This makes sense. Thank you @paritosh90.

fsouza avatar May 24 '12 14:05 fsouza

I'd like to be able to minify the Google Analytics <head> scripts inline without passing them off to Compressor with the other JavaScript files. I specifically don't want these in the output file generated by Compressor, nor in an external file at all.

venteto avatar May 03 '23 20:05 venteto