Skip to main content
added 48 characters in body
Source Link

Containing the PHP into a config data object goes 90% of the way but best practice is to seperate it entirely. You can use a RESTful api to only request the data that you need, it is a bit more javascript but with a few advantages.

  • Script is static and can be cached permanently
  • PHP no longer an XSS Vector
  • Complete seperation of concerns

Downsides:

  • Requires an extra HTTP request
  • more complex javascript

Script

//pure javascript $.on('domready',function({ //load the data $.get({ url:'/charts/3D1A2E', success: function(data){ //now use the chart data here ChartModule.init(data); } }); }) 

Containing the PHP into a config data object goes 90% of the way but best practice is to seperate it entirely. You can use a RESTful api to only request the data that you need, it is a bit more javascript but with a few advantages.

  • Script is static and can be cached permanently
  • PHP no longer an XSS Vector
  • Complete seperation of concerns

Downsides:

  • Requires an extra HTTP request
  • more complex javascript

Script

$.on('domready',function({ $.get({ url:'/charts/3D1A2E', success: function(data){ //now use the chart data here ChartModule.init(data); } }); }) 

Containing the PHP into a config data object goes 90% of the way but best practice is to seperate it entirely. You can use a RESTful api to only request the data that you need, it is a bit more javascript but with a few advantages.

  • Script is static and can be cached permanently
  • PHP no longer an XSS Vector
  • Complete seperation of concerns

Downsides:

  • Requires an extra HTTP request
  • more complex javascript

Script

//pure javascript $.on('domready',function({ //load the data $.get({ url:'/charts/3D1A2E', success: function(data){ //now use the chart data here ChartModule.init(data); } }); }) 
Source Link

Containing the PHP into a config data object goes 90% of the way but best practice is to seperate it entirely. You can use a RESTful api to only request the data that you need, it is a bit more javascript but with a few advantages.

  • Script is static and can be cached permanently
  • PHP no longer an XSS Vector
  • Complete seperation of concerns

Downsides:

  • Requires an extra HTTP request
  • more complex javascript

Script

$.on('domready',function({ $.get({ url:'/charts/3D1A2E', success: function(data){ //now use the chart data here ChartModule.init(data); } }); })