Remove whitespace in output HTML code

后端 未结 3 1255
臣服心动
臣服心动 2021-01-14 11:50

Consider test.cfm file with the following content:


    
        
            

        
相关标签:
3条回答
  • 2021-01-14 12:02

    If you have access to the CF Administrator, there is an option to suppress white space.

    It is under 'Server Settings' --> 'Settings' its called 'Enable Whitespace Management'.

    0 讨论(0)
  • 2021-01-14 12:03

    Try <cfprocessingdirective suppressWhiteSpace="true">

    Reference: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-76de.html

    0 讨论(0)
  • 2021-01-14 12:09

    Is there any way to fix this?

    There's nothing to fix - the HTML is perfectly valid and functional.

    If your issue is the size of request, use gzip encoding.

    If your issue is reading the source for debugging/etc, use developer tools such as Firebug/etc.


    However, general things you should be doing to improve maintainability (which at the same time also reduces whitespace output) are:

    1) Move anything that isn't display logic out of your views.

    2) Convert display logic to functions and custom tags as appropriate, which both make it easier to prevent/control output.


    To prevent unwanted content being output, you can:

    • Wrap the entire section in cfsilent, to ensure nothing gets output.

    • Enable enablecfoutputonly attribute of cfsetting then only use cfoutput around things you want to be output.

    • Always set output=false on component and function tags.

    • When you want to selectively output some text, wrap non-tag non-output segments in CFML comments <!---...---> (e.g. useful for preventing newline output in custom tags)

    (I never bother with cfprocessingdirective, everything mentioned above solves the issues better.)

    0 讨论(0)
提交回复
热议问题