简体   繁体   中英

JavaScript: from server to client

I am working on a project which involves building a web service on the top of a .js library. I successfully completed that but now I have create another library (or something) in which everything should be customizable from the client side and server should just provide the JavaScript functions so that client can attach them with buttons and work with them.

Right now, I can think of two possible implementations:

  1. Creating a new .js library and provide the functions which the client can use after including my .js file.

    (Overheads - client will still have to include other .js libraries which I am using inside my library...so frankly speaking, this is kind of overhead on the client and is probably not a good way to go about the problem). My server in this case will just process the data which will be used by my .js library on the client side.

  2. I directly return the necessary JavaScript functions along with the processed data so that client does not have to know about my internal implementation and can work with less overhead.

The problem is I don't know how to go about the second approach which looks quite promising. Is there any example implementation, or a better way to go about the first approach?

Ok. Let me try and explain this in my own words.

As far as I understood your problem, you do not want to include all the JS libraries in your code and would rather have the data passed to the JS libraries and then the inbuilt functions within your libraries process your data and return processed output .

I have not heard of this being done. Maybe it is so we can wait for an answer regarding that. But ideally what you would do is create a " Web service ".

So this " Web service " basically act's like your " external javascript function ". You pass data to the Web service and this data is processed and returned to you. You then process this output and display it the way you like.

So simply put, you will have to design a Web service with functions, that act the way your Javascript functions do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM