At the server side, there is a property file that contains a list of words separated by commas.
words.for.js=some,comma,separated,words
The goal is to convert these words into a JavaScript array.
var words = [some,comma,separated,words];
There are two approaches that I have considered:
1. Using a JSP scriptlet to create a global variable
<%
out.print("<script> var words = [");
out.print( PropertyLoader.getAsCommaSeparated("words.for.js") );
out.print(" ] </script>");
%>
2. Implementing a service/action (e.g., /getWords.do) and using AJAX to make a call in order to construct the array.
I am uncertain which approach is superior and would appreciate your insights. Is there perhaps a better way to achieve this task?
Thank you.
EDIT:
This also involves comparing a global JS variable (option 1) with an additional HTTP request (option 2) - which one is less optimal? Your perspective on this comparison would be valuable as well.