Remove whitespace in output HTML code

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

Consider test.cfm file with the following content:


    
        
            

        
3条回答
  •  南方客
    南方客 (楼主)
    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.)

提交回复
热议问题