在浏览器中引用CSS或JS加载本地文件 [英] Loading local file in browser referenced css or js
问题描述
这可能是一个基本的问题,但一些如何不为我工作。
This could be a basic problem but some how is not working for me.
下面是我的html:
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<base href="/">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="app/app.css"/>
</head>
<body ng-app="App">
<div> Hi There</div>
<script src="app/vendor.js"></script>
<script src="app/app.js"></script>
</body>
</html>
此文件位于:文件:///Users/kiran/Documents/app/dist/public/index.html
引用文件位于:
This file is located at: file:///Users/kiran/Documents/app/dist/public/index.html
Referenced files are located at:
app.css: file:///Users/kiran/Documents/app/dist/public/app/app.css
vendor.js: file:///Users/kiran/Documents/app/dist/public/app/vendor.js
app.js: file:///Users/kiran/Documents/app/dist/public/app/app.js
然而,当我尝试使用浏览器的打开文件>打开,它说,它无法与错误加载文件:
However, when I tried to open the file using browser->open, it says it cannot load the files with error:
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///app/app.css
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///app/vendor.js
Failed to load resource: net::ERR_FILE_NOT_FOUND file:///app/app.js
行为是在Firefox一样,虽然错误信息是不同的。我有什么做的,使工作?
鸭preciate的帮助。
Behavior is same in firefox though error message is different. What do I have to do to make it work? Appreciate the help.
请注意:当我运行一个Web服务器,但我需要与当地的引用和也的网络服务器这项工作它正常工作
Note: It works fine when I run a webserver, but I need to make this work with local references and also on webserver.
推荐答案
这是怎么回事becuause你有&LT;基地方式&gt;
标签
That's happening becuause you have <base>
tag.
The base URL to be used throughout the document for relative URL addresses.
由于基本URL href是'/',它总是从根本入手。因此,本地计算机上没有找到任何的CSS / JS文件,因为它会检查从根文件即 C / D / E盘
。而且它完全工作正常的网络服务器,因为根将是你的公用文件夹。
Since the base URL href is '/', it always start from root. So on local machine it doesn't find any css/js files, as it would check the files from root i.e. C/D/E drive
. And it totally works fine for webserver, since the root would be your public folder.
摆脱基地
标记。
这篇关于在浏览器中引用CSS或JS加载本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!