user1944934
user1944934

Reputation: 113

Javascript code from database/file

I would like to implement a plugin mechanism where js code is stored in a database and dynamically loaded into the class. A query for a specific plugin is performed, then the code resulting from the query is used to update a javascript class (functions and members).

So what I would achieve is that part of the class is loaded at startup from the JS class file and additional parts of the class are loaded from the db, and eventually unloaded, at runtime, giving it more functionalities.

Is this feasible? how to create a function from string? do you think it is a good approach?

JS Framework is ExtJS 4.1.1, database is postgres 9.2

Thanks

Upvotes: 1

Views: 135

Answers (1)

Lorenz Meyer
Lorenz Meyer

Reputation: 19935

I'm new to ExtJS, but I would not recommend this way to do.

  1. ExtJS has a recommended directory hierarchy and a command line build tool, that is powerful. Download it and play around with a test app. You will see if you can combine your approach with this. I really doubt. If you want to stick to your approach, you must somehow get it to be compatible with the basic requirements and recommandation of ExtJS application architecture.
  2. Think about maintainability. How do you update the code in your database ? Will the code in your development version also be in the DB ?
    Yes: This will be very impracticle for development
    No: Your build process will quite be heavy and convoluted.

My personal approach with plugins of the app is like this:

  1. In my database I store which user has access to which plugin. I also store dependecies. I send this information to the client in a simple array containing the list of the plugins the user is authorized to use.
  2. The application code is the same for everyone. This allows me to use one only minified javascript file, I build with the sencha app build command line.
  3. I load the plugins happens in the launch method of Ext.application what I'm doing is basicly add each plugin's menu to the main menu.
  4. To secure the access to the plugins, the whole php backend is secured to ensure that a user only can access a feature he is allowed to.

I hope this will give some inspiration to develop a more simple concept.

Upvotes: 1

Related Questions