-1

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?

1 Answers1

0

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.

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
  • Thanks for clarification, so is there any way I can remove dead code? – thirtythreeboas Feb 03 '23 at 11:39
  • @thirtythreeboas Rename your Scripts like _filename.js and examine, if the functionality is still complete. – Wolfgang Blessen Feb 03 '23 at 11:44
  • There are tools for JavaScript, but it won't be able to detect which functions are called from dynamically generated content. https://stackoverflow.com/questions/54148788/how-to-find-dead-code-in-a-large-react-project – Arnold Daniels Feb 03 '23 at 11:44
  • @thirtythreeboas I suggest considering this question as answered and asking a new question like "How can I find dead code in generated content?", where you go into this in-depth and add some examples. – Arnold Daniels Feb 03 '23 at 11:48