Skip to content

Commit c7723b2

Browse files
mkomorskiMarcin Komorski
andauthored
Loading modules separately (prebid#6353)
* Loading modules separately * lint * storage control usage --------- Co-authored-by: Marcin Komorski <marcinkomorski@Marcins-MacBook-Pro.local>
1 parent 30da2a8 commit c7723b2

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

_data/sidebar.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,14 @@
531531
sectionTitle:
532532
subgroup: 5
533533

534+
- sbSecId: 1
535+
title: Loading modules separately
536+
link: /dev-docs/modules/index.html#loading-modules-separately
537+
isHeader: 0
538+
isSectionHeader: 0
539+
sectionTitle:
540+
subgroup: 5
541+
534542
- sbSecId: 1
535543
title: External Interfaces
536544
link:

dev-docs/modules/index.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,49 @@ results. See [the userSync setConfig](/dev-docs/publisher-api-reference/setConfi
115115
</tbody>
116116
</table>
117117

118+
## Loading modules separately
119+
120+
There are situations where a publisher uses different modules depending on various factors, such as specific pages or locations. This creates the inconvenience of having to load a Prebid build that is larger than what a particular page actually needs. While it’s possible to work around this by creating separate Prebid builds for different pages, that approach doesn’t scale well. Since a Prebid build is composed of concatenated chunks, it’s possible to load modules separately, allowing you to have a main Prebid file that contains only the modules shared across all pages.
121+
122+
### Example
123+
124+
This is the example of loading modules separately for the self-hosted (e.g. CDN) Prebid build.
125+
Instructions for importing modules when using the npm package can be found in the [Readme file](https://github.com/prebid/Prebid.js/blob/master/README.md)
126+
127+
1. Perform full Prebid build `gulp build`
128+
1. Generate the main `prebid.js` file containing only the modules required across all pages: `gulp bundle --modules=<...>`
129+
1. Host `build/dist` folder content on your server or CDN
130+
1. Check the dependencies of the modules you plan to load dynamically on the current page [Dependency tree](https://cdn.jsdelivr.net/npm/prebid.js@latest/dist/chunks/dependencies.json)
131+
1. Load the required modules, their dependencies using script tags:
132+
133+
```html
134+
<html>
135+
<head>
136+
<title>Page 1</title>>
137+
<script src="https://<your-cdn>/prebid/ortbConverter.js"></script> <!-- Depedency of openxBidAdapter !-->
138+
<script src="https://<your-cdn>/prebid/openxBidAdapter.js"></script> <!-- Bid adapter module !-->
139+
<script src="https://<your-cdn>/prebid/id5IdSystem.js"></script> <!-- Another module (doesn't require any additional dependencies) !-->
140+
<script src="https://<your-cdn>/prebid/prebid.js"></script> <!-- Load prebid.js last !-->
141+
</head>
142+
```
143+
144+
### Storage control usage
145+
146+
When working with the `storageControl` module you will need to explicitly import disclosure metadata. To do this, pair each module import with its corresponding metadata file `<module>.metadata.js`
147+
148+
```html
149+
<html>
150+
<head>
151+
<title>Page 1</title>>
152+
<script src="https://<your-cdn>/prebid/ortbConverter.js"></script> <!-- Depedency of openxBidAdapter !-->
153+
<script src="https://<your-cdn>/prebid/openxBidAdapter.js"></script> <!-- Bid adapter module !-->
154+
<script src="https://<your-cdn>/prebid/openxBidAdapter.metadata.js"></script> <!-- Bid adapter module's metadata !-->
155+
<script src="https://<your-cdn>/prebid/id5IdSystem.js"></script> <!-- Another module (doesn't require any additional dependencies) !-->
156+
<script src="https://<your-cdn>/prebid/id5IdSystem.metadata.js"></script> <!-- Another module's metadata !-->
157+
<script src="https://<your-cdn>/prebid/prebid.js"></script> <!-- Load prebid.js last !-->
158+
</head>
159+
```
160+
118161
## Further Reading
119162

120163
- [Source code of all modules](https://github.com/prebid/Prebid.js/tree/master/modules)

0 commit comments

Comments
 (0)