Reading list Switch to dark mode

    Common Error in Production Mode When html is Minified

    Updated 5 January 2023

    Hello everyone, when you set production mode in your Magento 2 and minify the HTML files to speed your website, you often see an error like Parse errorsyntax error, unexpected ‘<‘, expecting end of file”

    or some Fatal error as in the below image –

    Or simply a blank screen.

    The cause of such errors is hidden in the template files. In the following commented code-

    <?php //echo "this is an unwanted php code";?>

    there is no space between the semicolon “;” and the closing tag of php i.e. “?>” which causes the error.

    Searching for an experienced
    Magento 2 Company ?
    Find out More

    For the above code, when the HTML file is minified, the closing tag of php is considered as a part of the commented code which is not included in the minified file and throws the error.

    So, while commenting a php code in a phtml file, make sure that there is a space before the closing tag of php as done in the code below-

    <?php //echo "this is an unwanted php code";  ?>

    Doing this will avoid the error due to minification of the HTML file.

    Hope this will help you.

    For any queries, feel free to comment below.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home