Skip to content

Commit d1b9ecd

Browse files
docs: precompress array rules and social media crawlers (#502)
* docs: precompress array rules and social media crawlers Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> * 📄 Update LLMs.txt snapshot for PR review --------- Signed-off-by: David Dal Busco <david.dalbusco@outlook.com> Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f6560be commit d1b9ecd

2 files changed

Lines changed: 91 additions & 16 deletions

File tree

.llms-snapshots/llms-full.txt

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ This `source` attribute works similarly to Git's `.gitignore`, and you can speci
18041804

18051805
### GZIP
18061806

1807-
When deploying your application, the CLI automatically searches for JavaScript (js), ES Module (mjs), CSS (css) and HTML (html) files in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
1807+
When deploying your application, the CLI automatically searches for files matching the pattern `**/*.+(css|js|mjs|html)` in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
18081808

18091809
By default, precompression stores **both** the original and compressed versions in Storage.
18101810

@@ -1814,7 +1814,7 @@ You can disable it entirely or customize which files are precompressed, whether
18141814

18151815
If you change the precompress configuration and your project has already been deployed, run `juno clear` before redeploying to ensure you change is applied.
18161816

1817-
## Disable precompression
1817+
#### Disable precompression
18181818

18191819
Set the `precompress` option to `false` in your configuration:
18201820

@@ -1824,7 +1824,7 @@ juno.config.js
18241824
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: false }});
18251825
```
18261826

1827-
## Customize the file matching pattern
1827+
#### Customize the file matching pattern
18281828

18291829
If you want to customize the default pattern `**/*.+(css|js|mjs|html)` to better suit your needs, you can specify your own pattern. For example:
18301830

@@ -1834,20 +1834,26 @@ juno.config.js
18341834
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { pattern: "**/*.jpg" // precompress JPEG files only } }});
18351835
```
18361836

1837-
## Decide what happens to original files
1837+
#### Decide what happens to original files
18381838

18391839
The `mode` option controls what happens to the original files after compression:
18401840

18411841
* `"both"` — upload both the original and the compressed version. _(default)_
18421842
* `"replace"` — upload only the compressed version and serve it with the appropriate `Content-Encoding` header.
18431843

1844+
**Warning:**
1845+
1846+
If you use `replace` for HTML, some social media crawlers (e.g. Twitter, LinkedIn) may not be able to fetch your pages correctly, resulting in missing or broken social previews.
1847+
1848+
To avoid this, instead of providing a single precompression rule, it's recommended to fine-tune the behavior using an **array of rules** (([see below](#use-multiple-rules))).
1849+
18441850
juno.config.js
18451851

18461852
```
18471853
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { mode: "replace" } }});
18481854
```
18491855

1850-
## Choose the compression algorithm
1856+
#### Choose the compression algorithm
18511857

18521858
By default, precompression uses **Gzip** (`algorithm: "gzip"`) because it offers a good balance between compression speed, compatibility, and size.
18531859

@@ -1859,6 +1865,18 @@ juno.config.js
18591865
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { algorithm: "brotli" } }});
18601866
```
18611867

1868+
#### Use multiple rules
1869+
1870+
In some cases, particularly when using `mode: replace`, you may want to apply different precompression strategies depending on the file type. For example, using replace for JavaScript and CSS files, but doing so for HTML can break social media previews.
1871+
1872+
To handle this, the precompress option also accepts an array of rules:
1873+
1874+
juno.config.js
1875+
1876+
```
1877+
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: [ { pattern: "**/*.+(js|mjs|css)", algorithm: "brotli", mode: "replace" }, { pattern: "**/*.html", algorithm: "brotli", mode: "both" } ] }});
1878+
```
1879+
18621880
### Encoding types
18631881

18641882
When deploying, the CLI automatically maps the encoding type based on the file extension. The encoding information is then used in the satellite to provide the appropriate HTTP response header `Content-Encoding`.
@@ -7724,7 +7742,7 @@ Usage: juno functions publish [options]Options: --no-apply Submit th
77247742
Upgrade your serverless functions.
77257743

77267744
```
7727-
Usage: juno functions upgrade [options]Options: --cdn Select a previously published WASM file from the CDN (interactive). --cdn-path Use a specific published WASM file from the CDN. --clear-chunks Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB). --no-snapshot Skip creating a snapshot before upgrading. -r, --reset Reset to the initial state. -s, --src A path to a specific local gzipped WASM file to publish. -h, --help Output usage information.Notes:- If no option is provided, the default local build output will be used.- If --src is specified, it takes precedence over any CDN options.- Use --cdn to interactively select from recent published releases.
7745+
Usage: juno functions upgrade [options]Options: --cdn Select a previously published WASM file from the CDN (interactive). --cdn-path Use a specific published WASM file from the CDN. -s, --src A path to a specific local gzipped WASM file to publish. --clear-chunks Clear any previously uploaded WASM chunks (applies if the WASM size is greater than 2MB). --no-snapshot Skip creating a snapshot before upgrading. -r, --reset Reset to the initial state. -m, --mode Choose which environment to use (production, staging, development). Defaults to production if omitted. -p, --profile Specify an optional profile to use (e.g. personal, team). Useful when managing multiple Mission Controls. --container-url Override a custom container URL. If not provided, defaults to production or the local container in development mode. --console-url Specify a custom URL to access the developer Console. -h, --help Output usage information.Notes:- If no option is provided, the default local build output will be used.- If --src is specified, it takes precedence over any CDN options.- Use --cdn to interactively select from recent published releases.
77287746
```
77297747

77307748
---
@@ -7905,7 +7923,7 @@ import { defineConfig } from "@junobuild/config";export default defineConfig({
79057923

79067924
### Precompress
79077925

7908-
When deploying your application, the CLI automatically searches for JavaScript (js), ES Module (mjs), CSS (css) and HTML (html) files in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
7926+
When deploying your application, the CLI automatically searches for files matching the pattern `**/*.+(css|js|mjs|html)` in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
79097927

79107928
By default, precompression stores **both** the original and compressed versions in Storage.
79117929

@@ -7915,7 +7933,7 @@ You can disable it entirely or customize which files are precompressed, whether
79157933

79167934
If you change the precompress configuration and your project has already been deployed, run `juno clear` before redeploying to ensure you change is applied.
79177935

7918-
## Disable precompression
7936+
#### Disable precompression
79197937

79207938
Set the `precompress` option to `false` in your configuration:
79217939

@@ -7925,7 +7943,7 @@ juno.config.js
79257943
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: false }});
79267944
```
79277945

7928-
## Customize the file matching pattern
7946+
#### Customize the file matching pattern
79297947

79307948
If you want to customize the default pattern `**/*.+(css|js|mjs|html)` to better suit your needs, you can specify your own pattern. For example:
79317949

@@ -7935,20 +7953,26 @@ juno.config.js
79357953
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { pattern: "**/*.jpg" // precompress JPEG files only } }});
79367954
```
79377955

7938-
## Decide what happens to original files
7956+
#### Decide what happens to original files
79397957

79407958
The `mode` option controls what happens to the original files after compression:
79417959

79427960
* `"both"` — upload both the original and the compressed version. _(default)_
79437961
* `"replace"` — upload only the compressed version and serve it with the appropriate `Content-Encoding` header.
79447962

7963+
**Warning:**
7964+
7965+
If you use `replace` for HTML, some social media crawlers (e.g. Twitter, LinkedIn) may not be able to fetch your pages correctly, resulting in missing or broken social previews.
7966+
7967+
To avoid this, instead of providing a single precompression rule, it's recommended to fine-tune the behavior using an **array of rules** (([see below](#use-multiple-rules))).
7968+
79457969
juno.config.js
79467970

79477971
```
79487972
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { mode: "replace" } }});
79497973
```
79507974

7951-
## Choose the compression algorithm
7975+
#### Choose the compression algorithm
79527976

79537977
By default, precompression uses **Gzip** (`algorithm: "gzip"`) because it offers a good balance between compression speed, compatibility, and size.
79547978

@@ -7960,6 +7984,18 @@ juno.config.js
79607984
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: { algorithm: "brotli" } }});
79617985
```
79627986

7987+
#### Use multiple rules
7988+
7989+
In some cases, particularly when using `mode: replace`, you may want to apply different precompression strategies depending on the file type. For example, using replace for JavaScript and CSS files, but doing so for HTML can break social media previews.
7990+
7991+
To handle this, the precompress option also accepts an array of rules:
7992+
7993+
juno.config.js
7994+
7995+
```
7996+
import { defineConfig } from "@junobuild/config";export default defineConfig({ satellite: { ids: { production: "qsgjb-riaaa-aaaaa-aaaga-cai" }, source: "dist", precompress: [ { pattern: "**/*.+(js|mjs|css)", algorithm: "brotli", mode: "replace" }, { pattern: "**/*.html", algorithm: "brotli", mode: "both" } ] }});
7997+
```
7998+
79637999
### Encoding
79648000

79658001
When deploying, the CLI automatically maps the encoding type based on the file extension. The encoding information is then used in the satellite to provide the appropriate HTTP response header `Content-Encoding`.

docs/build/components/precompress.mdx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
When deploying your application, the CLI automatically searches for JavaScript (js), ES Module (mjs), CSS (css) and HTML (html) files in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
1+
When deploying your application, the CLI automatically searches for files matching the pattern `**/*.+(css|js|mjs|html)` in the `source` folder to optimize them using Gzip compression. This improves the performance of your app when it is served on the web.
22

33
By default, precompression stores **both** the original and compressed versions in Storage.
44

@@ -10,7 +10,7 @@ If you change the precompress configuration and your project has already been de
1010

1111
:::
1212

13-
## Disable precompression
13+
#### Disable precompression
1414

1515
Set the `precompress` option to `false` in your configuration:
1616

@@ -28,7 +28,7 @@ export default defineConfig({
2828
});
2929
```
3030

31-
## Customize the file matching pattern
31+
#### Customize the file matching pattern
3232

3333
If you want to customize the default pattern `**/*.+(css|js|mjs|html)` to better suit your needs, you can specify your own pattern. For example:
3434

@@ -48,13 +48,21 @@ export default defineConfig({
4848
});
4949
```
5050

51-
## Decide what happens to original files
51+
#### Decide what happens to original files
5252

5353
The `mode` option controls what happens to the original files after compression:
5454

5555
- `"both"` — upload both the original and the compressed version. _(default)_
5656
- `"replace"` — upload only the compressed version and serve it with the appropriate `Content-Encoding` header.
5757

58+
:::warning
59+
60+
If you use `replace` for HTML, some social media crawlers (e.g. Twitter, LinkedIn) may not be able to fetch your pages correctly, resulting in missing or broken social previews.
61+
62+
To avoid this, instead of providing a single precompression rule, it's recommended to fine-tune the behavior using an **array of rules** ([see below](#use-multiple-rules)).
63+
64+
:::
65+
5866
```javascript title="juno.config.js"
5967
import { defineConfig } from "@junobuild/config";
6068

@@ -71,7 +79,7 @@ export default defineConfig({
7179
});
7280
```
7381

74-
## Choose the compression algorithm
82+
#### Choose the compression algorithm
7583

7684
By default, precompression uses **Gzip** (`algorithm: "gzip"`) because it offers a good balance between compression speed, compatibility, and size.
7785

@@ -92,3 +100,34 @@ export default defineConfig({
92100
}
93101
});
94102
```
103+
104+
#### Use multiple rules
105+
106+
In some cases, particularly when using `mode: replace`, you may want to apply different precompression strategies depending on the file type. For example, using replace for JavaScript and CSS files, but doing so for HTML can break social media previews.
107+
108+
To handle this, the precompress option also accepts an array of rules:
109+
110+
```javascript title="juno.config.js"
111+
import { defineConfig } from "@junobuild/config";
112+
113+
export default defineConfig({
114+
satellite: {
115+
ids: {
116+
production: "qsgjb-riaaa-aaaaa-aaaga-cai"
117+
},
118+
source: "dist",
119+
precompress: [
120+
{
121+
pattern: "**/*.+(js|mjs|css)",
122+
algorithm: "brotli",
123+
mode: "replace"
124+
},
125+
{
126+
pattern: "**/*.html",
127+
algorithm: "brotli",
128+
mode: "both"
129+
}
130+
]
131+
}
132+
});
133+
```

0 commit comments

Comments
 (0)