Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minifier html #549

Closed
oscarlosan opened this issue Feb 23, 2024 · 3 comments
Closed

Minifier html #549

oscarlosan opened this issue Feb 23, 2024 · 3 comments

Comments

@oscarlosan
Copy link

Hello, before I used the following function to minify my html and it worked for me. With flightphp it does not minimize the html. Is there something stopping ob_start?

`<?php
ob_start("minifier");
function minifier($code) {
$search = array(

    // Remove whitespaces after tags
    '/\>[^\S ]+/s',
     
    // Remove whitespaces before tags
    '/[^\S ]+\</s',
     
    // Remove multiple whitespace sequences
    '/(\s)+/s',
     
    // Removes comments
    '/<!--(.|\s)*?-->/'
);
$replace = array('>', '<', '\\1');
$code = preg_replace($search, $replace, $code);
return $code;

}`

@n0nag0n
Copy link
Collaborator

n0nag0n commented Feb 23, 2024

With the 3.5 release, we had to overhaul how the output buffer works. You have a couple options, some simpler than others to get it working again.

  1. Flight::set('flight.v2.output_buffering', true); https://docs.flightphp.com/learn/migrating-to-v3 - This will implement the default behavior you're likely used to.
  2. All the output is now written to the Flight::response()->body property. Although as I write this out, there isn't a way to completely overwrite the body without calling Flight::response()->clear() and then running your minified function on the existing body content.

As a side note, I didn't see you close the output buffer, which might be part of the issue? Usually there's something like a ob_end_clean(); to properly close the output buffer (which was part of the problem that was addressed in the 3.5 update).

@oscarlosan
Copy link
Author

Thank you very much for your support so quickly.

@n0nag0n n0nag0n closed this as completed Feb 24, 2024
@n0nag0n
Copy link
Collaborator

n0nag0n commented Apr 9, 2024

FYI. Created this pull request which might be what you're after if you want to fully move to v3. #571

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants