Jump to content

PHP / Javascript interaction - best practice?


vineld

Recommended Posts

Sometimes your Javascript code will need values generated by PHP right from the start. Usually I just print these values directly into the Javascript code since it's the quickest solution. What do the rest of you do, and more importantly, why?

 

I am currently trying to ease the workload for a few sites with high traffic and try to compress js code where it's possible but then I can of course not have any php code there. Perhaps it would be a good idea to store these key values in a hidden form? After all, that is a more flexible solution.

Depending on the situation, there's no harm in doing that.  The only thing that really does though is anchor js to a specific space in a script though.  Can't easily move that around, sort of thing (moreso from script to script vs. within script, but even then).  Using ajax is a bit more flexible.  You can have a script dedicated to handing out values for variables and that frees you up to do whatever on the rest of your page, without having to work around the javascript.  It also allows for multiple pages to draw from that single value controller script.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.