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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.