引用本地计算机上的 javascript 文件

发布于 2025-01-06 19:14:50 字数 1167 浏览 8 评论 0原文

我知道可以像这样引用网络上的第三方 JavaScript 文件:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

Is it possible to reference javaScript file on my local machine by do things like this?

<script src="file:///C:/folder/custom_javascript.js" type="text/javascript"></script>

我怀疑这可能是一个禁忌,因为它可能是网站找出客户端计算机上有哪些文件的一种方式...

我想这样做的原因是因为我正在开发一个 javaScript 密集型应用程序谷歌应用引擎。我希望能够运行和调试 javaScript 文件的修订版本,而不必每次进行更改时都重新上传它们。目前,每次我在 javascript 中更改某些内容时,我都必须:

  1. 进入我用来运行 javaScript 的 HTML 文件并更改文件名末尾的修订变量,以便旧版本不会缓存在某处: < code>
  2. 将整个应用程序上传到 Google 应用引擎
  3. 更改我在浏览器窗口中加载的 url 末尾的变量,这样我就不会获得该文件的缓存版本,该版本包含对其他 javascript 文件的缓存版本的引用:https:/ /my_app.appspot.com/index.html?revision=26
  4. 重新设置 Firefox 调试器中的所有断点,因为现在 Firefox 认为它正在处理不同的文件,因为“revision”变量不同。

这一切的结果就是我的注意力被打破,时间被浪费了。

我尝试使用 HTML 标头和浏览器本身中的缓存选项,但我认为这些文件可能由 google 和我的计算机之间的服务器缓存。

任何意见或想法将不胜感激!

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>

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...

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:

  1. 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>
  2. Upload the entire application to google app engine
  3. 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
  4. 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.

The result of all this is my concentration being broken and wasted time.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳哥哥 2025-01-13 19:14:50

不可以,您不能从非本地文件引用本地文件。最接近的解决方法是在您的计算机上设置本地服务器并链接到 localhost:

<script src="http://localhost/script.js"></script>

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>
此生挚爱伱 2025-01-13 19:14:50

对于每一个微小的变化都对应用程序进行全新的部署似乎太麻烦了。

您应该尝试在本地开发该应用程序。我猜您正在做这一切,因为您与 App Engine 紧密相连。但你至少应该能够在本地开发前端内容。

Doing a whole new deploy of your app for every little change seems like a way too much trouble.

You should attempt to develop the app locally. I guess you are doing all this because you are very bound to the App Engine. But you should at least be able to develop the frontend stuff locally.

青衫负雪 2025-01-13 19:14:50

第 1,3 点和第 4 点都可以通过按住 SHIFT 键并重新加载页面(或 CTRL + F5)。这告诉 Firefox 和所有介入的缓存您需要 HTML 和所有链接资源的全新副本。

Points 1,3 and 4 are all solved by holding down the SHIFT key and reloading the page (or CTRL + F5). This tells Firefox and all intervening caches that you want a fresh copy of the HTML and all linked resources.

逆夏时光 2025-01-13 19:14:50

您还可以以相对方式引用该文件,如下所示:
<脚本 src="scripts/chart.min.js">

You can also reference the file in a relative way, like so:
<script src="scripts/chart.min.js"></script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文