How do I optimize text retrieval?

Hello, I've got a script with a few options for the npc to say when spoken to. Right now I have the options in a bit of code inside of the event but I feel like that's a bit slow.

I plan on eventually having a lot of things the npc can say, so I would like the code to simply pull from a database in a text file. How would I go about doing that?
You can try to use some plugins that already do that like Dk tolls localization or Iavra localization.
The last one I made an upgrade and it includes a demo showing how to use it.
They can add a text inside an object in a JSON file.
So you have to simply call this object in your msgs:
{Map01.Npc01} - Something like that...
If it just retrieving data from outside (text, number, data, even function, etc)

Spoiler: The simplest DIY form
Here's a step by step.
I intent to make a tutorial of it anyway...
  1. Create a js file. Name it whatever you need. Put it inside yourgame/js/plugins folder
    1591339856887.png
  2. Activate it from your plugin manager
    1591339872353.png
  3. Use any text editor you like (I use Notepad++). Open the file, then write a self called function.
    1591339975079.png

  4. Make an object. Name it whatever you want.
    1591340146738.png

  5. Let's make a sample first...
    1591340329101.png
  6. It's done. Your "text" already stored. You may directly access it using game variables.
    1591340423605.png
  7. Result :
    1591340453443.png
Spoiler: Further : How to write escape code
Let's start by writing another sample :
1591340579115.png

Red : Any code from window message shall start with \x1b
Cyan : Code to write in new line (enter). \n
Purple : Code to write in new page (window). \f
Green : Use backslash beforehand to write single quote character (').

Result :
text example.gif

EDIT : I already made the tutorial.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-optimize-text-retrieval.122465/