Can i write over a module js file in Magento 2?

  • What are the cons doing it?
  • Are there any build in functions that allows me to write to a modules file (I know php allows it).

The problem - I have data in database that I want to use in autocomplete field. The idea is that when the data gets updated in databases then Magento 2 overwrites the file where the array of the file is stored? Are there any cons when the array contains about 100+ variables?

What would demand more resource, fetching data from db with ajax or storing it in a js file?

1 Answer 1


I would keep the data in the Database and use a Block Cache to cache the inline javascript data as part of the page HTML.

Then when a user updates the database model (save, delete, etc), you just invalidate that cache... and the next page load for the frontend will regenerate the HTML with the new DB info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.