使用php检查是否已加载javascript文件? [英] using php to check is a javascript file has been loaded?

查看:87
本文介绍了使用php检查是否已加载javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用脚本来检查是否加载了JS文件吗?

Can I use a script to check if a JS file is loaded?

我有一个函数,它将一个表单放在一个带有javascript控件的页面上。我不知道用户将在何处使用此表单,并且可能会多次加载到页面中。如果表单本身加载脚本,它会成为处理事物的最佳方式,因此如果不需要它就不会加载,但这导致我需要检查脚本是否已经加载以避免重新加载并添加到页面加载时间和带宽的使用。

I have a function, which places a form on a page with javascript controls. I don't know where the user will use this form, and it might be loaded several times into a page. It strikes me as the best way to handle things if the form itself loads the script, so it doesn't load if not needed, but this leads me to need to check if the script is already loaded to avoid reloading and adding to page load times and bandwidth use.

推荐答案

没有。在PHP脚本刷新所有输出之后才会看到该页面,到那时为止已经太晚了。但是大多数浏览器足够聪明,无论如何都只能在每页加载一次外部资源。

No. The page isn't seen until the PHP script has flushed all its output, by which time it's too late to do anything. But most browsers are smart enough to only load an external resource once per page anyway.

这篇关于使用php检查是否已加载javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆