In PHP, I would save the js file as jeditable.js.php, and the server would compile the code that is in the tag.
Keep in mind that php is now forced to process the entire javascript file for each request. This is usually "Bad Thing" TM and it uses server resources that can be spent elsewhere.
As already mentioned in Raj Kimal's answer, what we do in ASP.Net to deal with this most efficient way is a short script defined in a line with a page that does nothing but assign variables to the result of the server code. Do this before declaring other scripts, and you can use these variables directly in these scripts. This way you do not need to do extra server work for external javascript files.
I will make one addition to Mr. Kimal. Often it is best to enclose these variables in an object to avoid name collisions. Something like that:
<head runat="server"> <script language="javascript"> var ServerCreated = { ArticleAction:'<%=Url.Action("UpdateSettings","Article") %>', OtherVar:'some server data' } </script> </head>
Then your jeditable.js file will look like this:
$(document).ready(function() { $(".naslov_vijesti").editable(ServerCreated.ArticleAction, { submit: 'ok', submitdata: {field: "Title"}, cancel: 'cancel', cssclass: 'editable', width: '99%', placeholder: 'emtpy', indicator: "<img src='../../Content/img/indicator.gif'/>" }); });
source share