Best-practice for javascript configuration on new web project Best-practice for javascript configuration on new web project json json

Best-practice for javascript configuration on new web project


  • Must define a global variable or json or javasctipt object or array (I don't know which is best)

JSON is basically an object literal, so it can do both. Go for it. Think of JSON as a serialized javascript object.

  • This values must reachable by other javascript functions and objects.

As soon as you run the JSON it will be available in your code.

  • Will store booleans, strings, integers maybe a some little initialization methods for 5-6 different pages (ex.: we don't need main page's config values on product detail page's and we don't need product detail page's some initialization methods and values on main page etc.)

Again, JSON can do all of that.

So I would suggest a JSON file, that is included via script tag on the client side. JSON is easy to generate, read and manipulate on the server side (eg.: json_encode, json_decode in php).

It SHOULD BE a static js file, as it stresses the server the least. Also, Gzip compression can help to keep the bandwidth cost low.