何时使用 url 以及何时使用路径
是否存在经验法则,在哪些情况下我应该使用 URl,在哪些情况下应该使用路径?
示例:
C:\some-path\to-my\local-dev-environment\xampp\whatever
vs.
http://localhost/whatever
code>
编辑: 我想要实现的是一个“安全”列表,在这种情况下我应该使用/避免使用 和 URl 以及我应该使用/避免路径。补充:它对性能有什么影响?
Is there a rule of thumb in which cases I should use an URl and in which a path?
Example:
C:\some-path\to-my\local-dev-environment\xampp\whatever
vs.
http://localhost/whatever
EDIT: What I want to acchieve is a "safe" list in which cases I should use/avoid using and URl and in which I should use/avoid a path. Additional: What impact on performance does it have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上是一个访问问题。
如果相关实体可以合法访问您的文件系统,则使用该路径。
如果该实体无权访问您的文件系统,但您仍然想通过网络技术授予他某种访问权限,则使用 URL。
编辑
性能:
路径始终具有更高的性能,因为它通常在同一台计算机(服务器)或至少在同一 Intranet 上使用。除此之外还绕过 URL 使用的 Web 协议。
URL 始终被认为性能较差,因为请求是通过 HTTP、FTP 或其他协议进行路由的,然后将请求转换为 Path 请求,然后将文件发送到最终目的地。所以您应该意识到,所有 URL(文件)请求最终都会转换为 Path。从这个意义上说,URL只是通过网络技术访问另一台计算机的路径的另一种方式。
“安全”列表(不全面):
使用
使用路径进行
或多或少这里是一般规则拇指。
如果您可以在不使用 URL 的情况下导航到该文件,那么您可能应该通过程序访问该文件。
It's really a question of access.
If the entity in question has legitimate access to your file system then go with the path.
If the entity does not have access to your file system, but you would still like to grant him some sort of access via a web technology, then go with a URL.
EDIT
Performance:
The Path is always be more performant since it is generally used on the same computer (server) or at least on the same intranet. Aside from also bypassing the Web protocols used by URLs.
The URL is always considered less performant since the request is being routed through an HTTP,FTP, or other protocol which then converts the request to a Path request and then serves the file to the end destination. So what you should realize is that all URL (file) requests eventually get converted to a Path. In this sense, URL is just another way to access the Path of another computer via a web technology.
"Safe" list (not comprehensive):
Use URLs for
Use Path for
More or less here is here general rule of thumb.
If you can navigate to the file without using a URL that's probably how you should access it with your program.
在代码中使用服务器端路径时使用路径。
在编写链接、重定向等 URL 时使用 URL。
Use the path when using paths server side in code.
Use the URL when composing URLs such as links, redirects, etc.
URL通常用于访问全局资源,如http、ftp链接,而路径则用于访问本地资源,如本地文件等。
URL are generally used for accessing global resources like http, ftp links, where as path for local resources like local files etc.