• jasghar

    (@jasghar)


    Hi, I am making a WordPress website and I have a js file in it by the time the file is getting bigger and bigger sometimes it’s very hard for me to find code from a file so I just want to know if there’s a way we can organize js code into code chunks. Just like we do in SCSS and react [we place code in separate files so everything be more organizable and easy]
    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t know of a structured way to do so with straight JS. Naturally you could break up your JS into separate files and conditionally enqueue each as needed for a particular situation. This works OK as a site specific solution, but for a generic plugin that needs to work on any site, we end up blindly enqueuing everything all the time because it’s difficult to know where our scripts will actually be needed.

    I often wish plugins would offer some way for site admins to specify when scripts are needed or not. I end up having to write custom code to dequeue scripts when they are not needed. It would have been better if they were never enqueued to start with, except where really needed. But such a UI for site admins would likely confuse more people than it would help.

Viewing 1 replies (of 1 total)
  • The topic ‘How to organize my js code?’ is closed to new replies.