Skip to content

Commit ee4dce0

Browse files
gaearonalexdriaguine
authored andcommitted
Clarify when to use the public folder
1 parent 2d29372 commit ee4dce0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

packages/react-scripts/template/README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ You can find the most recent version of this guide [here](https://github.com/fac
2222
- [Post-Processing CSS](#post-processing-css)
2323
- [Adding Images and Fonts](#adding-images-and-fonts)
2424
- [Using the `public` Folder](#using-the-public-folder)
25+
- [Changing the HTML](#changing-the-html)
26+
- [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system)
27+
- [When to Use the `public` Folder](#when-to-use-the-public-folder)
2528
- [Using Global Variables](#using-global-variables)
2629
- [Adding Bootstrap](#adding-bootstrap)
2730
- [Adding Flow](#adding-flow)
@@ -373,7 +376,18 @@ An alternative way of handling static assets is described in the next section.
373376

374377
>Note: this feature is available with `[email protected]` and higher.
375378
376-
Normally we encourage you to `import` assets in JavaScript files as described above. This mechanism provides a number of benefits:
379+
### Changing the HTML
380+
381+
The `public` folder contains the HTML file so you can tweak it, for example, to [set the page title](#changing-the-page-title).
382+
The `<script>` tag with the compiled code will be added to it automatically during the build process.
383+
384+
### Adding Assets Outside of the Module System
385+
386+
You can also add other assets to the `public` folder.
387+
388+
Note that we normally we encourage you to `import` assets in JavaScript files instead.
389+
For example, see the sections on [adding a stylesheet](#adding-a-stylesheet) and [adding images and fonts](#adding-images-and-fonts).
390+
This mechanism provides a number of benefits:
377391

378392
* Scripts and stylesheets get minified and bundled together to avoid extra network requests.
379393
* Missing files cause compilation errors instead of 404 errors for your users.
@@ -410,7 +424,15 @@ Keep in mind the downsides of this approach:
410424
* Missing files will not be called at compilation time, and will cause 404 errors for your users.
411425
* Result filenames won’t include content hashes so you’ll need to add query arguments or rename them every time they change.
412426

413-
However, it can be handy for referencing assets like [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest) from HTML, or including small scripts like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code.
427+
### When to Use the `public` Folder
428+
429+
Normally we recommend importing [stylesheets](#adding-a-stylesheet), [images, and fonts](#adding-images-and-fonts) from JavaScript.
430+
The `public` folder is useful as a workaround for a number of less common cases:
431+
432+
* You need a file with a specific name in the build output, such as [`manifest.webmanifest`](https://developer.mozilla.org/en-US/docs/Web/Manifest).
433+
* You have thousands of images and need to dynamically reference their paths.
434+
* You want to include a small script like [`pace.js`](http://github.hubspot.com/pace/docs/welcome/) outside of the bundled code.
435+
* Some library may be incompatible with Webpack and you have no other option but to include it as a `<script>` tag.
414436

415437
Note that if you add a `<script>` that declares global variables, you also need to read the next section on using them.
416438

0 commit comments

Comments
 (0)