rubyrequireopalrb

How and where does the `require_table` variable get stored? (OpalRb)


So, I was recently reading through the require system of OpalRb, and came across the interesting require_table variable. Reading through the methods there, it's clear that require_table is used to see whether a file has already been loaded or not, for methods like require or loaded. But, I'm not sure how or where this variable gets stored. Wouldn't the opal/corelib/runtime.js file just get reloaded once the browser reloads the page, thus resetting require_table's value? I guess I'm just trying to better understand how require works with the dynamics of a browser.


Solution

  • The require table is defined here and yes, the runtime is reloaded when the browser is reloaded. That's normal as the whole HTML page starts from scratch reloading all of its assets and thus reloading Opal and its dependencies too.

    It's impossible anyway to persist live objects through requests, the best you can do is to persist some data (e.g. with localStorage) but of course that has nothing to do with loaded libs and can at best be used to save requests (don't do that! or you would re-invent HTTP cache).