因此,假设您有一个基于 React 的移动 Web 应用程序,它利用服务器端呈现的初始视图(出于速度 + SEO 原因)。没有“index.html”文件——索引文件在服务器端动态构建并在初始响应中返回。
现在假设您想向该应用程序添加 PWA 功能。你连接了一个 service worker 来缓存资产等。
PWA 的核心租户之一是它们提供离线体验。假设我们只想在 Service Worker 检测到用户离线时显示一个刷新页面,“您离线,单击此处刷新”。
谷歌提供的在线示例谈论使用 App Shell——一个静态 HTML 文件,它可以在初次访问时由服务工作者缓存,它将成为你的反应应用程序所在的“外壳”。此外壳与显示“离线”视图有关。
这如何与服务器端渲染一起工作,其中没有“shell”html 文件,并且每个路由都可能返回不同的 index.html 文件?
任何有关此功能的演示或示例?
reactjs service-worker server-side-rendering progressive-web-apps app-shell
我是 React 的新手。我正在构建一个带有 react、react router4、react redux 等的站点,其中很少有组件在服务器上呈现(主要是使用 API 调用获取数据并显示它们)。现在我的问题是,如果我在服务器上呈现组件并将呈现的 HTML 发送到客户端,它会再次在客户端上呈现(进行 API 调用),我需要阻止这种情况。
如果组件已经在服务器上呈现,我不想再次呈现它。我怎样才能做到这一点?
谢谢
萨蒂什
我有一个 React Web 应用程序,它使用 SSR 在页面请求时将包提供给浏览器。
我的问题是我可以通过 CDN 保存包,以便从 CDN 提供页面请求并加载到浏览器中吗?
首先在 CDN 上缓存包是一个好习惯吗?
另外,CDN 如何知道我已经更新了代码,我是否需要故意使 CDN 缓存失效?
我们在 Docker 中运行 Next.js。
在本地构建镜像并使用生产后端时,TTFB 几乎为零,但是当我们部署此镜像时,TTFB 在某些情况下可能长达 30 秒。
生产服务器是不需要启动的暖服务器。
我运行了四项测试,以使用相同的生产后端针对相同的路线测量 TTFB。
yarn build && yarn startyarn run dev在 docker 内外测试生产模式时,TTFB 接近于零。
在开发模式下本地测试时,TTFB 几乎与生产相同。
我已经通过 SSH 进入生产环境并确认没有安装开发包,所以我认为我们不可能在开发模式下运行。
我希望生产 TTFB 更接近我们在当地所经历的。
什么可能导致本地和生产之间的差异?
文件
FROM node:10.13.0-alpine
WORKDIR /app
EXPOSE 8080
CMD [ "yarn", "start" ]
COPY . .
RUN yarn install
RUN yarn build
Run Code Online (Sandbox Code Playgroud)
server.js 片段
const express = require('express');
const next = require('next');
const cookieParser = require('cookie-parser');
const jwtDecode = require('jwt-decode');
const { …Run Code Online (Sandbox Code Playgroud) 我试图做SSR与ReactDOMServer.renderToNodeStream(element)只是想知道是否有将与同时使用的任何问题ReactDOMServer.renderToString(element),并 ReactDOMServer.renderToNodeStream(element)在每个请求?
我在自定义 SSR 设置中拥有的是:* React 16 * react-loadable * styled-components v4 * react-helmet-async * Redux * Express JS
以前使用 React,我可以通过首先渲染<head></head>包含由React生成的标记的标签,react-helmet然后使用它ReactDOMServer.renderToString()来渲染我的 React 元素来轻松渲染 HTML 文档。
但是,通过切换到ReactDOMServer.renderToNodeStream()我不得不切换react-helmet为react-helmet-async,它支持renderToNodeStream()功能。但是当我尝试<head></head>用标记渲染标签时,react-helmet-async它会返回为undefined.
为了解决这个问题,我不得不先使用,renderToString()而没有将它实际写到 Express JS 中response。这样react-helmet-async就可以看到要呈现哪些元标记,然后继续使用renderToNodeStream并将其流式传输到response.
我已经尽可能地简化了我的代码,因为我想了解这是否会产生负面影响(对于性能,或者是否有人能想到其他任何事情)?
前:
let html = ReactDOMServer.renderToString(stylesheet.collectStyles(
<Loadable.Capture report={moduleName => modules.push(moduleName)}>
<LocalStoreProvider store={store}>
<HelmetProvider context={helmetContext}>
<RouterContext …Run Code Online (Sandbox Code Playgroud) javascript reactjs server-side-rendering styled-components react-helmet
I'm working on an laravel project. There're a lot of vue components and I need to make SSR due to SEO. I can't use nuxt.js or something like it because of my app is not SPA. I have default mix settings:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.sass', 'public/css');
mix.disableSuccessNotifications();
Run Code Online (Sandbox Code Playgroud)
I put the vue components to laravel views (blade templates) like <example-component></example-component>. How may I implement SSR for there components only in this case?
I need to add this …
我正在编写一个基于 React 的应用程序,它使用 SSR 生成适合搜索引擎和初始客户端负载的内容,并在客户端使用 React.hydrate()。都好。
在带有标签的页面上,我在 img 上同时使用 src、srcSet 和 size 属性,以允许客户端选择合适的图像大小。再次,一切都很好。
但是,至少在 Safari 中,当同时使用 src 和 srcSet 时,会加载 src 资源以及相关的 srcSet 资源。我可以在浏览器网络检查器中看到这一点。删除 src 属性会导致浏览器仅加载 srcSet 资源之一。
虽然我可以修复客户端,但这意味着 img 标签在搜索引擎爬虫方面不完整,没有 src 属性。我假设爬虫不使用 srcSet 但我想他们可以这样做。我可以通过使用具有空 SVG 或 1x1 GIF/PNG 的 src 属性的数据 URI 使 img 标记更加完整,但这无助于确保爬虫可以访问适当分辨率的图像资源。网站的性质至少表明图像资源应该可以在搜索引擎上找到,作为一种将访问者吸引到适当内容的方式。
我查看了几个延迟加载 React 组件,它们似乎都遇到了这个问题或其他问题的某种组合。
有谁知道这是否是 Safari 特定的错误,或者是否有针对客户端延迟加载时图像 SSR 的通用解决方案?理想情况下,在不调用次优客户端行为的 SSR 生成代码上,src、srcSet 和大小的首选组合是什么?
注意:延迟加载是可取的,因为它的图片库/索引页面包含大量图像,而移动/低带宽是一个关键的人群。
我在 azure devops 上有一个带有 .net core 和 angular 的应用程序。现在,我想实现 Angular Universal SSR。
然后,我在我的项目上做了:
ng 添加@nguniversal/express-engine --clientProject angular.io-example
我的 package.json 是:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "npm run build:client-and-server-bundles && npm run compile:server",
"build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"bundle-report": "ng build --extract-css --stats-json && webpack-bundle-analyzer dist/stats.json",
"compile:server": "webpack --config webpack.server.config.js --progress --colors",
"serve:ssr": "node dist/server",
"build:client-and-server-bundles": "ng build --extract-css --prod && ng run Catevering:server:production"
}
Run Code Online (Sandbox Code Playgroud)
然后,我可以在 …
server-side-rendering azure-devops asp.net-core angular-universal
我有一个使用 Vue CLI v3 创建的相当复杂的 SPA Vue.js 应用程序。我想转换这个应用程序以从 SSR 中受益(尽管我最终可能只使用预渲染......)
我的应用程序也在使用通过 CLI v3 创建的自定义 Vuejs 库。这些库嵌入了 CSS,我想继续这样做。
我可能已经阅读了世界上关于 Vue cli、vue-loader、vue-style-loader、vue.config.js、提取 css 等的所有内容,但我一直失败。
这是我加载给定路线时正在运行的应用程序的错误消息:
ReferenceError: document is not defined
at addStyle (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:699:22)
at addStylesToDom (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:683:20)
at addStylesClient (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:637:3)
at Object.3351 (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:500:14)
at __webpack_require__ (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:21:30)
at Object.d12e (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:3590:380)
at __webpack_require__ (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:21:30)
at Module.fae3 (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:3859:51)
at __webpack_require__ (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:21:30)
at /Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:85:18
at Object. (/Users/onekiloparsec/code/my-app/node_modules/vue-custom-lib/dist/vue-custom-lib.common.js:88:10)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
Run Code Online (Sandbox Code Playgroud)
单击错误的第一行时,我从commonjs我的 lib 文件中获得以下代码: …
我想使用 SSR 来改进我的 angular 单页应用程序的搜索引擎优化。我通过使用 Angular-Universal 启用了 SSR,它正在为静态 html 提供服务,但我的组件严重依赖异步 api 调用来构建页面上的内容。请参阅下面的示例,其中$obs在ngOnInit函数中初始化然后与管道一起使用,这些调用在客户端进行,然后加载内容。这不是我想要的,因为我需要 api 调用中的内容来生成元标记。是否可以强制 angular Universal 等待 api 调用完成,使用此数据呈现 html,然后提供静态 html?asynchtml 中管道一起使用以提取数据。我遇到的问题是 SSR 提供的静态 html 不包含任何使用async
@Component({
selector: 'app-example-component',
template: `
<div *ngIf="(obs$ | async) as model">
{{model.title}}
</div>
`
})
export class ExampleComponent implements OnInit {
obs$: Observable<SomeModel>;
constructor(private exampleHttpService: ExampleHttpService) {}
ngOnInit() {
this.obs$ = this.exampleHttpService.doSomeApiCall();
}
}
Run Code Online (Sandbox Code Playgroud)
我希望 SSR 使用来自 api 调用的标题呈现模板 html,然后提供该静态 html。
reactjs ×6
vue.js ×2
angular ×1
app-shell ×1
asp.net-core ×1
azure-devops ×1
cdn ×1
html ×1
http ×1
image ×1
javascript ×1
laravel ×1
lazy-loading ×1
next.js ×1
react-helmet ×1
react-redux ×1
vue-cli-3 ×1
vue-ssr ×1
vuejs2 ×1
web ×1