Jump to content

minify HTML issue


The Little Guy

Recommended Posts

Currently I use this to "Minify" my html:

 

$template = preg_replace("/\s\s+/", "", $template);
$template = preg_replace("/\r|\n/isU", "", $template);
$template = preg_replace("/\t/isU", "", $template);

 

I just found an issue that I didn't think of when writing this, within textarea's that gets minified too. so all the places where a newline would be within the textarea is now gone and when putting default data into a textarea mulitline functionality is gone.

 

What can I do to preserve newlines in the textarea, yet still minify?

Link to comment
https://forums.phpfreaks.com/topic/263824-minify-html-issue/
Share on other sites

Use DOM to rewrite the HTML. It's not just textareas you have to treat specially: there's scripts, styles, and PREs for starters. And inline CSS is worth mentioning.

 

Oh, and you're removing \s\s+? So if I type two spaces and/or newlines somewhere they're both lost?

Link to comment
https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1351935
Share on other sites

I'm saying that the minimizing will break code like

function update(v) {
    document.getElementById('id').value = v
    document.getElementById('other').value = v
}

as well as styles like

body  p {
    text-decoration: blink;
}

style="border: 2px  solid blue"

Link to comment
https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1351985
Share on other sites

I guess with the "\s\s+" I could remove all space into 1 space, so that wouldn't break.

 

But we have been going though code making sure there are semi-colons on everything in the js.

 

I feel, if you can't minify js and css without errors (after comments are removed) then your doing something wrong.

Link to comment
https://forums.phpfreaks.com/topic/263824-minify-html-issue/#findComment-1352190
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.