Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Move all <style> tags from <body> to <head>
Is there some possibility to move all <style> tags from <body> to <head> ?
Maybe using <liferay-util:buffer var="html"> and then:
That code remove all styles tags from output HTML but I need to cut and insert that tags in <head> section.
Maybe using <liferay-util:buffer var="html"> and then:
<% html = html.replaceAll("(?s)<style>.*?</style>", ""); %>
That code remove all styles tags from output HTML but I need to cut and insert that tags in <head> section.
First question: Why? Is it really necessary?
Can you identify the places where this happening? Maybe you can "kill them" at the source. There is a tag, that adds things to the head of the page and maybe you can fix it where the tags are added.
If the style tags are inside of portlets then you could intercept them. Liferay renders all portlets and stores them in a buffer. Later, in the theme that buffer content is inserted into the page. You probably could get in there somewhere and modify that buffer or do the replacement. Please note that this will incur some performance penalty.
Can you identify the places where this happening? Maybe you can "kill them" at the source. There is a tag, that adds things to the head of the page and maybe you can fix it where the tags are added.
If the style tags are inside of portlets then you could intercept them. Liferay renders all portlets and stores them in a buffer. Later, in the theme that buffer content is inserted into the page. You probably could get in there somewhere and modify that buffer or do the replacement. Please note that this will incur some performance penalty.
Marcin Klinski:
Seconding Christoph.
Is there some possibility to move all <style> tags from <body> to <head> ?
You seem to be on a quest rewriting significant portions of the rendered HTML, and doing so you'll end up with unique opportunities to see failures that nobody else sees, and that nobody else will have a chance to help you on.
You've chosen a platform in order to take away a lot of infrastructure burden. I understand that you personally would have made different choices in various places. But you made the (wise) choice to build on a platform. Now you would have all the time in the world to work on actual business problems, rather than on infrastructure. But you choose not to, and worry about tiny technical beauty aspects.
In case it's not a beauty aspect, and you're on to something big and structurally important, I'd like to see the root problem discussed and fixed, rather than String.replace bandaid applied.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™