Skip to content

Commit e2ceb11

Browse files
authored
fix(Lazy-loading dfp ads): Implement lazy-loading for dfp ads (#85)
* Pass index to eagerload collection images * chore(release): 1.57.5-uday-perf.0 * Eargerload only first collection instead of first two * chore(release): 1.57.5-uday-perf.1 * Pass predicate to EagerLoadImages * chore(release): 1.57.5-uday-perf.2 * Lazy-load ads Enable single request * chore(release): 1.57.5-uday-perf.3 * Set singleLoad to false * chore(release): 1.57.5-uday-perf.4 * Remove lazyLoading and enable singleLoad * chore(release): 1.57.5-uday-perf.5 * Enable lazy-loading and disable single-request * chore(release): 1.57.5-uday-perf.6 * Remove eager loading collection wrapper * Update package-lock * chore(release): 1.57.5-uday-perf.7 * chore(release): 1.57.5-uday-perf.8 * Pass lazyLoad and singleRequest as props * Update Readme * chore(release): 1.57.5-uday-perf.9 * chore(release): 1.57.5-uday-perf.10
1 parent e34fdd2 commit e2ceb11

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ import { ClientSideOnly } from '@quintype/components';
111111
```
112112

113113
### DfpAds
114-
This is a higher order component which can be used to manage ad units in a single place. A component must be created, and used with the `adtype` parameter
114+
This is a higher order component which can be used to manage ad units in a single place. A component must be created, and used with the `adtype` parameter. These ads are lazy-loaded and single-request mode is disabled by default which can be overwritten as follows.
115115

116116
```javascript
117117
import { createDfpAdComponent } from '@quintype/components';
@@ -130,7 +130,10 @@ export const DfpAd = createDfpAdComponent({
130130
// if(storyIsSponsored) params['sponsor'] = storySponsor
131131

132132
return params;
133-
}
133+
},
134+
// Only if you want to overwrite the existing values
135+
lazyLoad: false,
136+
singleRequest: true
134137
});
135138

136139
<DfpAd adtype="homepage-2" />

src/components/dfp-ad.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@ import {AdSlot, DFPSlotsProvider} from 'react-dfp';
33
import {connect} from 'react-redux';
44
import {withError} from './with-error';
55

6-
function DfpAdBase({defaultNetworkID, config, collapseEmptyDivs, targetingArguments, adtype}) {
6+
function DfpAdBase({defaultNetworkID, config, collapseEmptyDivs, targetingArguments, adtype, lazyLoad, singleRequest}) {
77
const adConfig = config[adtype];
88
return <DFPSlotsProvider dfpNetworkId={defaultNetworkID}
99
collapseEmptyDivs={collapseEmptyDivs}
1010
targetingArguments={targetingArguments}
11-
sizeMapping={adConfig.viewPortSizeMapping}>
11+
sizeMapping={adConfig.viewPortSizeMapping}
12+
lazyLoad={lazyLoad}
13+
singleRequest={singleRequest}>
1214
<AdSlot {...adConfig} />
1315
</DFPSlotsProvider>;
1416
}
1517

16-
export function createDfpAdComponent({defaultNetworkID, config, targeting, collapseEmptyDivs = true}) {
18+
export function createDfpAdComponent({defaultNetworkID, config, targeting, collapseEmptyDivs = true, lazyLoad = true, singleRequest = false}) {
1719
return connect((state) => ({
1820
targetingArguments: targeting(state),
1921
defaultNetworkID: defaultNetworkID,
2022
config: config,
21-
collapseEmptyDivs: collapseEmptyDivs
23+
collapseEmptyDivs: collapseEmptyDivs,
24+
lazyLoad: lazyLoad,
25+
singleRequest: singleRequest
2226
}), () => ({}))(withError(DfpAdBase));
2327
}

0 commit comments

Comments
 (0)