引用本地计算机上的javascript文件 [英] Referencing javascript files on my local machine
问题描述
我知道可以像这样引用网络上的第三方JavaScript文件:
I know that its possible to reference third party JavaScript files on the web like so:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
是否可以通过执行以下操作来引用本地计算机上的javaScript文件?
Is it possible to reference javaScript file on my local machine by doing something like this?
<script src="file:///C:/folder/custom_javascript.js" type="text/javascript"></script>
我怀疑这可能是不行,因为这可能是网站发现的一种方式客户端计算机上有哪些文件...
I suspect this may be a no-no, since it could be a way for websites to find out what files are on a client's computer...
我之所以想这样做,是因为我正在Google App Engine上开发大量JavaScript应用程序。我希望能够运行和调试JavaScript文件的修订版本,而不必每次进行更改时都重新上传它们。当前,每次更改javascript中的内容时,我都必须:
The reason I would like to do this is because I am developing a javaScript-heavy application on google app engine. I'd like to be able to run and debug revisions to my javaScript files without having to re-upload them every time I make a change. Currently, every time I change something in the javascript, I have to:
- 进入用于运行JavaScript的HTML文件并在文件名的末尾更改修订变量,以使旧版本不会缓存在某处:
< script src = resource / custom / js / the_file_im_working_with.js?revision = 76 type = text / javascript>< / script>
- 将整个应用程序上传到google app引擎
- 更改我在浏览器窗口中加载的url末尾的变量,这样我就不会得到该THAT文件的缓存版本,该文件包含对其他javascript文件的缓存版本的引用:
https:/ /my_app.appspot.com/index.html?revision=26
- 重新设置Firefox调试器中的所有断点,因为现在Firefox认为它可以处理不同的文件,因为修订变量不同。
- Go into the HTML file that I am using to run the javaScript and change a revision variable at the end of the filename so that the old version is not cached somewhere:
<script src="resource/custom/js/the_file_im_working_with.js?revision=76" type="text/javascript"></script>
- Upload the entire application to google app engine
- Change a variable at the end of the url that I am loading in my browser window so that I don't get a cached version of THAT file holding a reference to the cached version of the OTHER javascript file:
https://my_app.appspot.com/index.html?revision=26
- Re-set any break points in the Firefox debugger because now Firefox thinks its dealing with a different file since the "revision" variable is different.
所有这些操作的结果是我的注意力被打破了std时间。
The result of all this is my concentration being broken and wasted time.
我尝试在HTML标头和浏览器本身中使用缓存选项,但是我认为文件可能已被Google之间的服务器缓存和我的计算机。
I tried playing around with caching options in the HTML headers and in the browser itself, but I think the files may be being cached by a server somewhere between google and my computer.
任何输入或想法都将不胜感激!
Any input or ideas would be much appreciated!
推荐答案
否,您不能从非本地文件引用本地文件。最接近的解决方法是在计算机上设置本地服务器并链接到 localhost
:
No, you cannot reference a local file from a non-local file. The closest workaround would be to set up a local server on your machine and link to localhost
:
<script src="http://localhost/script.js"></script>
这篇关于引用本地计算机上的javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!