Overwriting file vs fetching from db

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?

Solutions

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.

Similar questions

overwriting adminhtml block from another extension doesn't work
I'm trying to find a solution since a couple hours now. Unfortunately without any luck, so I need to ask you for help. I'm trying to add a download button to a grid which will be provided by an extension. If I'm customize the concerning file in Block/Adminhtml/O directly the button shows up (Add a button to admin grid). But I don't want to customiz...
modman overwriting our whole directory, how does it merge with existing contents?
we have the following modman file set-up The problem is that for example overwrites all directories. app/locale/* on github contains De_de and en_us directories. These directories already contain files on the Magento server. Now how can I make modman, clone all files from github in match app/locale/* --- but then merge with already existing files, ...
Overwriting Core Shipping Block
Im working on a Magento job and its been a while since I have dabbled in the dark arts. Im currently writing a small bit of script that will override the shipping methods on the checkout screen. You will have to excuse any mediocrity in my code as I said its been a while. So I have two files: app/code/local/ClarkStudios/Shipmentfilter/etc/config.xm...
Prevent Magento from overwriting URL key
I have the following problem with my products in Magento. Once I upload products and save them initially the URL key field stays empty and the product just gets a URL like www.mysite.com/SKU However once I change something in the product and save it again it changes the URL to And it also writes the product name in the URL key. Is there a way I can...
Overwriting mage core create.php
I'm attempting to overwrite adminhtml/model/sales/order/create.php, specifically public function initFromOrderItem. Text output shows the function I've overwritten is not loading to the site. In app/etc/modules/GoddessDelivers_QObugfux.xml In app/code/local/GoddessDelivers/QObugfix/etc/config.xml In app/code/local/GoddessDelivers/QObugfix/Adminhtml...
Overwriting community controller from local
Let's say I wan't to override a community module named Aaa_Aaa with local module named Zzz_Zzz. It seems that no matter what I do, my local module loads after the community one, so the community module is matched first. I tried this: app/code/local/Zzz/Zzz/controllers/IndexController.php app/etc/modules/Zzz_Zzz.xml

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.