在下载到客户端计算机之前预处理Javascript [英] Pre-Process Javascript before downloading to client machine
问题描述
我想在下载客户端浏览器之前预处理javascript文件。我用css文件成功完成了这个,但是当我对我的javascript文件应用相同的标准时,它不起作用。
I want to pre-process a javascript file before downloading it the client browser. I have done this successfully with a css file, but when I apply the same criteria to my javascript file it does not work.
有谁知道如何使用PHP预先在下载之前处理一个.js文件?
Does anyone know how to use PHP to pre-process a .js file before download?
谢谢
推荐答案
创建一个文件,假设 jsfile.js.php
:
header("Content-type: text/javascript");
ob_start("ob_gzhandler");
include('jsfile.js');
ob_flush();
现在不包括.js文件,只需包含此.php文件即可。
Now instead of including .js file, just include this .php file.
小编辑(在我看到您的评论后):
如果只是添加变量,您可以在html中定义它们,就在包含js文件之前:
Small edit (after I saw your comment): If is only about added variables, you can define them in html, just before including the js file:
var timestamp = "<?php echo time(); ?>
<script src="jsfile.js"></script>
这篇关于在下载到客户端计算机之前预处理Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!