Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

virgiltu's avatar

New CSS for amp

Ok so I was not able to find what I was looking and thus I decided to create my own package. But I need a bit of guidance.

What I built so far.

So far I build a package that will take the rendered HTML page from blade and dump out all the ID and Class styles. Than it will take the css files added to public/css and parse it out. It than compares them and put them only the used classes and Ids in a new file called public/ampcss/style.css . As a last step it will take this file and include it in the head of html with an amp format.

Ok what I am trying to do, is to get this to run each time a view is rendered in dev mode. But in production to run only when I call it.

Why I build this. There are other packages like uncss and csspurify. I know. But you need to have node installed. The issue is that my scrip will be a clone of opencart and aimed to people that use share hosting and have no access to node. Also because what I add a new module on the home page or what ever page, i will need to run laravel mix again and again, where if you are on shared hosting you cant.

Also because I find it stupid to need nodejs as I am building a larvel app. I wanted a native plugin.

Where I need help.

Any ideas how to set this to run with every rendered view? I think this was done as middleware if I am not mistaken. Is that correct?

0 likes
3 replies
virgiltu's avatar

@MSTRAUSS - I decided to make a package and just use middelware. I might put it on github once it is working in my project 100%. It all works now but i need to add a few more thing to make it faster.

However your message came at the perfect time as I was looking to build a menu and the data view share was something i was just looking for.

mstrauss's avatar

@virgiltu, Cool, be sure to share the project on Laracasts when it's ready, I'd like to check it out.

Please or to participate in this conversation.