跨(子)域维护资产的最佳实践?

发布于 2024-12-03 04:58:45 字数 791 浏览 3 评论 0原文

我的网络服务器文件系统相当于以下内容:

/master-domain.tld
/master-domain.tld/assets/js/foo.js
/master-domain.tld/assets/css/bar.css

/sub1.master-domain.tld
/sub1.master-domain.tld/assets/js/foo.js

/sub2.master-domain.tld
/sub1.master-domain.tld/assets/css/bar.css
...

我想知道的是如何将我的公共静态资产(托管在主域上)提供给我的子域 - 原因是我只需要维护一组“ master' 资产,而不是每次编辑任何文件时将其更新/复制到所有其他子域。显然,这可以使用绝对 URL 来实现,但我的目标是避免这些,以便我的本地/开发系统在设计/调试时不需要进行任何远程调用。

目前,我为每个子域设置了 mod_rewrite + 符号链接 + php 脚本组合,将对不存在的本地资产的任何调用链接到主资产。例如,调用“/sub1.master-domain.tld/assets/css/bar.css”将检索托管在 master 域上的 bar.css 文件,因为 bar.css 的本地版本不存在。此外,调用“/sub1.master-domain.tld/assets/js/foo.js”将提供 foo.js 的本地版本,因为它确实存在。

但我当前的方法似乎阻碍了页面加载的性能,我想知道是否有更好的(仍然是模块化的)方法来解决这个问题。

有什么建议吗?我是否以完全错误的方式处理这件事?

My webserver filesystem is equivalent to the following:

/master-domain.tld
/master-domain.tld/assets/js/foo.js
/master-domain.tld/assets/css/bar.css

/sub1.master-domain.tld
/sub1.master-domain.tld/assets/js/foo.js

/sub2.master-domain.tld
/sub1.master-domain.tld/assets/css/bar.css
...

What I'd like to know is how to serve my common static assets (hosted on the master domain) to my subdomains-- reason being that I then only have to maintain a single set of 'master' assets, rather than update/copy any files to all other subdomains each time I edit them. Obviously this can be achieved using absolute URLs, but my aim is to avoid these so that my local/dev system needn't make any remote calls while I'm designing/debugging.

Currently, I have a mod_rewrite + symbolic link + php script combo set up for each subdomain, linking any calls to non-existent local assets to the master assets. e.g. calling "/sub1.master-domain.tld/assets/css/bar.css" will retrieve the bar.css file hosted on the master domain since a local version of bar.css does not exist. Furthermore, calling "/sub1.master-domain.tld/assets/js/foo.js" would serve the local version of foo.js, since it does exist.

But my current method seems to be hindering the performance of my page loads, and I wonder if there is a better (still modular) approach to solving this problem.

Any tips? Am I going about this in completely the wrong way?

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

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

发布评论

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

评论(3

极度宠爱 2024-12-10 04:58:45

如果它们都位于同一服务器上,则只需符号链接即可。这应该不会造成任何性能影响。例如,

/sub1.master-domain.tld/assets -> /master-domain.tld/assets

如果您的子域由多个服务器提供服务,我将设置一个 mod_rewrite 规则,其中 302 重定向到主域上的完整 URL。在该主域服务器上,我将设置 mod_expires 以便缓存资产,从而避免对子域上相同“丢失”资产的大多数后续请求。

Symbolic links should be all that's required if they're all on the same server. This should cause no performance hits at all. E.g.

/sub1.master-domain.tld/assets -> /master-domain.tld/assets

If your subdomains are served from multiple servers, I would set up a mod_rewrite rule with 302 redirects to the complete URL on the master domain. On that master domain server I would set mod_expires so the assets are cached, avoiding most subsequent requests to the same "missing" assets on the subdomains.

诗化ㄋ丶相逢 2024-12-10 04:58:45

如果它们位于同一台计算机上,为什么不将不同的虚拟主机别名指向同一文档根目录呢?

If they are on the same machine, why not point different virtual host aliases to the same document root?

十秒萌定你 2024-12-10 04:58:45

我会使用保留静态。子域用于此目的,并针对该子域的所有请求。

I'd use reserved static. subdomain for this purpose and aim all request on that one.

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