Question

I was looking at thenextweb's team page and found that inside < head>, they are including an external php file within the < script> tag. Is this a good practice ? And what might be the purpose of doing this ?

URL: http://thenextweb.com/about/team/

Code:

<script type="text/javascript" src="/about/php/scriptsData.php"></script>
Was it helpful?

Solution

JavaScript files need not have the .js extension. Sometimes you need to generate JavaScript dynamically and you end up with a .php file. For example, for placing markers in a Google map with the API, I generated the JavaScript file with php (fetching the marker locations from a database) rather than using some sort of AJAX. There's nothing wrong with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top