diff --git a/packages/next/next-server/lib/post-process.ts b/packages/next/next-server/lib/post-process.ts
index 04c9ad8225720..01e99bcc53dff 100644
--- a/packages/next/next-server/lib/post-process.ts
+++ b/packages/next/next-server/lib/post-process.ts
@@ -191,10 +191,7 @@ class ImageOptimizerMiddleware implements PostProcessMiddleware {
acc + ``,
''
)
- return result.replace(
- /', imagePreloadTags)
}
}
diff --git a/packages/next/next-server/server/config-shared.ts b/packages/next/next-server/server/config-shared.ts
index 3b94c9d8b854f..8a355647d1d47 100644
--- a/packages/next/next-server/server/config-shared.ts
+++ b/packages/next/next-server/server/config-shared.ts
@@ -113,7 +113,7 @@ export const defaultConfig: NextConfig = {
stats: false,
externalDir: false,
reactRoot: Number(process.env.NEXT_PRIVATE_REACT_ROOT) > 0,
- disableOptimizedLoading: true,
+ disableOptimizedLoading: false,
gzipSize: true,
craCompat: false,
},
diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx
index 19ef353bb41f7..57d95097eea19 100644
--- a/packages/next/pages/_document.tsx
+++ b/packages/next/pages/_document.tsx
@@ -705,6 +705,9 @@ export class Head extends Component<
{!process.env.__NEXT_OPTIMIZE_CSS && (
)}
+ {process.env.__NEXT_OPTIMIZE_IMAGES && (
+
+ )}
{!disableRuntimeJS &&
!disableJsPreload &&
this.getPreloadDynamicChunks()}
diff --git a/test/integration/app-document-import-order/test/index.test.js b/test/integration/app-document-import-order/test/index.test.js
index 0876420e7dbe4..4db9f4b1f1d3c 100644
--- a/test/integration/app-document-import-order/test/index.test.js
+++ b/test/integration/app-document-import-order/test/index.test.js
@@ -61,11 +61,11 @@ describe('Root components import order', () => {
const chunks = Array.from($('head').contents())
.filter(
(child) =>
- child.type === 'tag' &&
- child.name === 'link' &&
- child.attribs.href.match(requiredByRegex)
+ child.type === 'script' &&
+ child.name === 'script' &&
+ child.attribs.src.match(requiredByRegex)
)
- .map((child) => child.attribs.href.match(requiredByRegex)[1])
+ .map((child) => child.attribs.src.match(requiredByRegex)[1])
const requiredByAppIndex = chunks.indexOf('requiredByApp')
const requiredByPageIndex = chunks.indexOf('requiredByPage')
diff --git a/test/integration/basic/test/dynamic.js b/test/integration/basic/test/dynamic.js
index c7600d7ea1505..11074a8391ab3 100644
--- a/test/integration/basic/test/dynamic.js
+++ b/test/integration/basic/test/dynamic.js
@@ -219,7 +219,7 @@ export default (context, render) => {
const $ = await get$('/dynamic/multiple-modules')
const html = $('html').html()
try {
- expect(html.match(/chunks[\\/]hello1\.js/g).length).toBe(2) // one for preload, one for the script tag
+ expect(html.match(/chunks[\\/]hello1\.js/g).length).toBe(1)
expect(html).not.toMatch(/hello2\.js/)
} catch (err) {
console.error(html)
diff --git a/test/integration/disable-js/test/index.test.js b/test/integration/disable-js/test/index.test.js
index 05748b81a9cef..4c277dd860e33 100644
--- a/test/integration/disable-js/test/index.test.js
+++ b/test/integration/disable-js/test/index.test.js
@@ -83,11 +83,7 @@ describe('disabled runtime JS', () => {
const $ = cheerio.load(html)
expect($('script#__NEXT_DATA__').length).toBe(1)
})
- it('should have preload links', async () => {
- const html = await renderViaHTTP(appPort, '/')
- const $ = cheerio.load(html)
- expect($('link[rel=preload]').length).toBeGreaterThan(0)
- })
+
it('should have a script for each preload link', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
diff --git a/test/integration/dynamic-routing/test/index.test.js b/test/integration/dynamic-routing/test/index.test.js
index 2b0054ce3784e..ac8f7842a0d60 100644
--- a/test/integration/dynamic-routing/test/index.test.js
+++ b/test/integration/dynamic-routing/test/index.test.js
@@ -952,20 +952,6 @@ function runTests(dev) {
expect(res.status).toBe(400)
})
- it('should preload buildManifest for auto-export dynamic pages', async () => {
- const html = await renderViaHTTP(appPort, '/on-mount/hello')
- const $ = cheerio.load(html)
- let found = 0
-
- for (const el of Array.from($('link[rel="preload"]'))) {
- const { href } = el.attribs
- if (href.includes('_buildManifest')) {
- found++
- }
- }
- expect(found).toBe(1)
- })
-
it('should not preload buildManifest for non-auto export dynamic pages', async () => {
const html = await renderViaHTTP(appPort, '/hello')
const $ = cheerio.load(html)
diff --git a/test/integration/production/test/index.test.js b/test/integration/production/test/index.test.js
index a9f4f9db8f112..570bbe0eecb4d 100644
--- a/test/integration/production/test/index.test.js
+++ b/test/integration/production/test/index.test.js
@@ -895,7 +895,7 @@ describe('Production Usage', () => {
}
})
- it('should have async on all script tags', async () => {
+ it('should have defer on all script tags', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
let missing = false
@@ -909,7 +909,7 @@ describe('Production Usage', () => {
continue
}
- if (script.attribs.defer === '' || script.attribs.async !== '') {
+ if (script.attribs.defer !== '' || script.attribs.async === '') {
missing = true
}
}
diff --git a/test/integration/script-loader/test/index.test.js b/test/integration/script-loader/test/index.test.js
index 8a90b9389e4ff..8913b83160099 100644
--- a/test/integration/script-loader/test/index.test.js
+++ b/test/integration/script-loader/test/index.test.js
@@ -42,20 +42,14 @@ describe('Script Loader', () => {
async function test(id) {
const script = await browser.elementById(id)
- const src = await script.getAttribute('src')
const endScripts = await browser.elementsByCss(
`#${id} ~ script[src^="/_next/static/"]`
)
- const endPreloads = await browser.elementsByCss(
- `link[rel=preload][href="${src}"] ~ link[rel=preload][href^="/_next/static/"]`
- )
// Renders script tag
expect(script).toBeDefined()
// Script is inserted at the end
expect(endScripts.length).toBe(0)
- //Preload is defined at the end
- expect(endPreloads.length).toBe(0)
}
// afterInteractive script in page
@@ -102,31 +96,13 @@ describe('Script Loader', () => {
function test(id) {
const script = $(`#${id}`)
- const src = script.attr('src')
// Renders script tag
- expect(script).toBeDefined()
- // Preload is inserted at the beginning
- expect(
- $(
- `link[rel=preload][href="${src}"] ~ link[rel=preload][href^="/_next/static/"]`
- ).length &&
- !$(
- `link[rel=preload][href^="/_next/static/chunks/main"] ~ link[rel=preload][href="${src}"]`
- ).length
- ).toBeTruthy()
-
- // Preload is inserted after fonts and CSS
- expect(
- $(
- `link[rel=stylesheet][href^="/_next/static/css"] ~ link[rel=preload][href="${src}"]`
- ).length
- ).toBeGreaterThan(0)
+ expect(script.length).toBe(1)
// Script is inserted before NextScripts
expect(
- $(`#__NEXT_DATA__ ~ #${id} ~ script[src^="/_next/static/chunks/main"]`)
- .length
+ $(`#${id} ~ script[src^="/_next/static/chunks/main"]`).length
).toBeGreaterThan(0)
}