Common Error in Production Mode When html is Minified
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 error: syntax 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.
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.