Referencing javascript files on my local machine

丶灬走出姿态 提交于 2020-01-05 04:01:05

问题


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!


回答1:


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>



回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/9356165/referencing-javascript-files-on-my-local-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!