Best Way to include javascript in java servlets

后端 未结 2 1344
悲&欢浪女
悲&欢浪女 2021-02-09 08:10

i actually read a tutorial about servlets and i saw two different ways to include javascript in servlets.

  out.println(\"\");

  Request         


        
2条回答
  •  误落风尘
    2021-02-09 08:23

    When we use the RequestDispatcher, we are actually making request from the server for the said JS file and then we embed it into the response document.

    On the other hand, embedding a tag will point the browser to make such a request to the server. I guess both the approaches are going to fetch the same results 99% of time at least if your file is on different server.

    On the other hand, if it is on the same server, I think RequestDispatcher will be faster.

    Server side caching will help in first approach and client side one in other.

提交回复
热议问题