简体   繁体   English

在javascript src属性中定义php文件是什么意思?

[英]what is the mean of defining php file in javascript src property?

I found this script somewhere on a web page which has external php file linked in script tag. 我在某个网页的某个位置找到了该脚本,该脚本的脚本标签中链接了外部php文件。 I googled it but nothing found useful. 我用谷歌搜索,但没有发现有用的东西。 can anyone make me understand about this? 谁能让我了解这一点?

<script type="text/javascript" src="file.php"></script>

Below is the content of file.php 以下是file.php的内容

Bootstrapper._serverTime = '2015-08-01 11:50:50'; 
Bootstrapper._clientIP = '103.39.117.145'; 
Bootstrapper.callOnPageSpecificCompletion();
Bootstrapper.setPageSpecificDataDefinitionIds([])

Yes, it's not an unknown practice, many CMS's as well as projects use an "endpoint" or a "script" dedicated to handle the frontend resources. 是的,这不是一个未知的实践,许多CMS以及项目都使用专用于处理前端资源的“端点”或“脚本”。

They can perform tasks such as minification of resources into one single chunk, or just plain concatenation of resource files into one. 他们可以执行任务,例如将资源压缩成一个单一的块,或者将资源文件简单地串联成一个块。

As long as anything (script or endpoint) outputs javascript, or in this case echo 's javascript, it can be used referred in a script tag. 只要任何内容​​(脚本或端点)都输出javascript,或者在这种情况下为echo的javascript,就可以在script标记中引用它。

Note - This requires the script or endpoint to handle output headers as well, which is commonly done by sending in a Content-Type header along the response 注意-这也要求脚本或端点也处理输出标头,通常是通过在响应中发送Content-Type标头来完成的

In PHP it's usually done using header('Content-Type: application/javascript'); 在PHP中,通常使用header('Content-Type: application/javascript');

在我看来,在给定的情况下, File.php可以简单地动态生成javascript代码(例如,从数据库中加载一些JS等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM