I have a rather typical PHP project in which the header/footer parts of pages are reused and therefore placed in separate files that I simply require from the main file.
This means, however, that my _header.php-file ends in an open <article> tag (which is then "closed" at the beginning of _footer.php).
The problem is that htmlmin interprets this as an error on my part and adds closing article, body and html tags in _header.php. How do I 'disable' that? I've read through the GitHub pages of grunt-contrib-htmlmin and html-minifier without much luck.
My Task Config
htmlmin: {
dist: {
options: {
minifyJS: true,
removeComments: true,
collapseWhitespace: true
},
files: {
'staging/index.php': 'index.php',
'staging/support/index.php': 'support/index.php',
'staging/inc/_header.php': 'inc/_header.php',
'staging/inc/_footer.php': 'inc/_footer.php'
}
}
}
Bonus brownie points if you can also tell my why minifyJS: true seems to be ignored
Thanks.
I searched for a solution, I looked at the documentation, I read several blog posts and I found out that at this time what you are asking is impossible.
Moreover someone asked a similar question on GitHub, Support for html fragments, but it was closed with the answer:
So this is not possible and this is (probably) not going to be implemented in the future.
You can't block that process (with grunt-contrib-htmlmin) because their intent is to specifically prevent users from leaving "uncorrect code".
I did not find any other equivalent grunt-plugin that gives you that possibility.
In the end I think you have only two "solutions" left:
1)Not minifying your php fragments;
2)Divide your code into more parts, minify only the one without unclosed tags, and reunite them all using grunt-include-replace, or a similar plugin, in a new php file.