Search code examples
javascriptphpdead-code

How can I remove dead JS code sent to the browser by PHP?


Well, I made a little research and decided to remove dead code with Tree Shivering, but it turned out that all JS scripts with HTML are sent by PHP to the browser and it doesn't work with npm run build or something. I don't know how to remove dead code, if only manually. The project runs on Open Server and I can't see what is going on on my terminal. Any suggestions?


Solution

  • The PHP runs serverside, the JavaScript clientside.

    The JavaScript is never called by PHP. Instead, it's send to the client (the browser) together with the HTML generated by PHP. The browser executes the JavaScript.

    A method like Tree Shivering, will not be able to tell you what part of the JS is not used.