我面临着一个问题,我的网站部署使用Primeng阿波罗主题.当我在本地运行站点时,只加载了一次heme.css文件和preloading.css文件,一切都很顺利.然而,当我实时部署站点时,主题.css和preloading.css文件都被多次加载.这不是我想要的行为.

Can anyone assist me in resolving this issue? I need help to ensure that the theme.css and preloading.css files are loaded correctly when deploying the site live. Thank you in advance for any guidance or suggestions you can provide. first loading

我预计在实时部署期间的行为与在本地运行站点时的行为相同,在本地运行站点时只会加载一次heme.css和preloading.css文件.

推荐答案

如果对所有文件使用无缓存,就会发生这种情况,我们的项目就是这种情况.

我用了这个 deploy-an-angular-app-with-nginx

您应该只缓存css和js文件,不能缓存index.html.

location ~ /index.html|.*\.json$ {
      expires -1;
      add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
}

location ~ .*\.css$|.*\.js$ {
      add_header Cache-Control 'max-age=31449600'; # one year
}

location / {
      try_files $uri$args $uri$args/ /index.html;
      add_header Cache-Control 'max-age=86400'; # one day
}

Angular相关问答推荐

在Angular 17中加载页面时打开打印对话框

Angular 信号不更新afterNextender()

仅在从forkJoin获得数据后订阅主题

Swiper 11角17 SSR Swiper断点不工作

对子router-outlet 应用主机样式

截获火灾前调用公共接口

如果Rxjs间隔请求仍在进行,则不应重置,但如果用户更改输入,则应重置

RxJS轮询+使用退避策略重试

Angular将文件作为字符串读取给dxf解析器

在switchMap操作符中使用条件语句以进行第一次或随后的执行

手动关闭 SSE 连接:Angular

当访问令牌在 MSAL for Angular 中过期时如何重定向用户?

在Angular 4中有条件地应用点击事件

可从 Angular2 中的

Angular [disabled]="MyBoolean" 没有工作

如何在 Angular Cli 中生成 .angular-cli.json 文件?

具有多个订阅者的 Angular 2 Observable

angular2 测试,我如何模拟子组件

Hot and Cold observables:有 hot和 cold运算符吗?

Angular 2 中的动态模板 URL