Code Monkey home page Code Monkey logo

Comments (7)

jaap3 avatar jaap3 commented on July 30, 2024

This is somewhat of an edge case. {% compress %} blocks are usually only wrapped around the lines needing compression, as far as I know it actually "eats" all non CSS/JS related HTML.

If you really need to be able to compress CSS/JS in malformed HTML (and you are unable to fix the template for some reason) you'll indeed need to change your parser to the much heavier BeautifulSoup. In most cases the 'dumb' HtmlParser works just fine.

from django-compressor.

camilonova avatar camilonova commented on July 30, 2024

Not always, if you try to compress clean html, not malformed, it breaks too, and it usually the use of html templating using javascript is getting more used this days.

Besides, why the compressor cant handle simple html? otherwise, will be a better option not to try compress html inside javascript??

from django-compressor.

bendavis78 avatar bendavis78 commented on July 30, 2024

Same thing happens with me exactly as camilonova said. Even of you have clean html inside of a string, it breaks, and ends up truncating the javascript file at that point, leading to mysterious javascript errors.

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

Could you try wrapping the javascript in a html comment? so:
<script><!-- alert('javascript'); //--></script>

I'm currently unable to try this myself, but it might work...If not you could try swapping the parser to a more robust, but slower one:
COMPRESS_PARSER = 'compressor.parser.BeautifulSoupParser'

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

So while I'm not sure if this can be fixed for good, it'd be good to at least warn users of the behavior and explain to use a different parser instead. What do you think?

from django-compressor.

camilonova avatar camilonova commented on July 30, 2024

I think a warn is just good.

from django-compressor.

jedie avatar jedie commented on July 30, 2024

This problem has other guys, too: gregmuellegger/django#1

The real problem is here: http://bugs.python.org/issue670664 and has pachtes...

EDIT: I tried http://bugs.python.org/file22767/hp_fix.diff from http://bugs.python.org/issue670664 and this seems to fix this issues!

I add the patch in my django-tools with: jedie/django-tools@aa722b3 django-compressor can do this, too.

from django-compressor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.