Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
793 views
in Q2A Core by
how to minify output with/without plugin?

qa-cachning is not working, if possible I'd like to edit core files directly.
by
There are many method for reducing server load and improving display performance. qa-cachning is one method for unregistered users. You will need to make it clear that you want to do.

For example of FlexArmor2:
view-source:http://askive.cmsbox.jp/demo/bm/

This theme equipped features below. But, not yet equipped HTML cache feature.
 1. HTML compression
 2. CSS minify
 3. JS minify

1 Answer

0 votes
by
In your qa-theme.php file add this function:
 
public function output_array($elements) {
  foreach ($elements as $element) {
    $delta = substr_count($element, '<') - substr_count($element, '<!') - 2*substr_count($element, '</') - substr_count($element, '/>');
    if ($delta < 0)
      $this->indent += $delta;
    echo str_replace('/>', '>', $element);
    if ($delta > 0)
      $this->indent += $delta;
    $this->lines++;
  }
}
 
Or, the core hack version, locate qa-theme-base.php and just change this line: https://github.com/q2a/question2answer/blob/cc22ed461de4b0ce560b0f82617d3e7baf543b4d/qa-include/qa-theme-base.php#L92 with the one with this one:
 
echo str_replace('/>', '>', $element);
 
Size of the activity list for only 2 questions (more questions more saving): 2900. After removing the indents: 2622. If you also want to remove indents of JS you'll have to locate "\t" in the core and remove them.
 
Bear in mind, spaces, sadly, affect the thems and styles... so something might break. Actually, IMO, they would be fixed as the themes won't depend on spacing but you'll have to modify the CSS a little.
by
edited by
You should keep the new line at the end:
echo str_replace('/>', '>', $element)."\n";

That will solve the space issue. Minifying HTML should only collapse all whitespace to one space character, not remove it entirely.

Edit: also the output_raw function needs changing too, and any blank lines could be removed.

Welcome to the Q&A site for Question2Answer.

If you have a question about Q2A, please ask here, in English.

To report a bug, please create a new issue on Github or ask a question here with the bug tag.

If you just want to try Q2A, please use the demo site.

Categories

...