28
loading...
This website collects cookies to deliver better user experience
browserslist
will take care of it.node_modules
from transpilation, as it decreases build time significantly.
However, you may find for TVs that many modules over time drop support for browsers you simply have to continue supporting.
You can include the whole node_modules
in transpilation, but we've found including only a handful of modules with the issues works well.
Ie:
include: [
path.resolve(__dirname, 'src'),
{
include: path.resolve(__dirname, 'node_modules'),
or: [/wonka/, /vtt-to-json/, /serialize-error/, /joi-browser/, /whatwg-fetch/],
},
],
browserslist
, you might need an if
to apply different styling or similar here and there, but that's about it.import { exitApplication } from '../../utils/device/device';
// .... call exitApplication in some event handler
/device
|- device.lg.js
|- device.tizen.js
|- device.xbox.js
|- device.vizio.js
env.platform
variable.function platformizeExtensions(platform, extensions) {
return [...extensions.map(extension => `.${platform}${extension}`), ...extensions];
webpack.config.js
resolve: {
extensions: platformizeExtensions(env.platform, [
'.mjs',
'.js',
'.jsx',
'.scss',
]),
},
['.lg.mjs', '.lg.js', '.lg.jsx', '.lg.scss', '.mjs', '.js', '.jsx', '.scss'];
import { exitApplication } from '../../Utils/device/device';
will import from device file for the platform, ie on LG it will import from device.lg.js
.device.*.js
will have to export methods with the same name, otherwise you might encounter an error trying to import something that doesn't exist on some platforms.export const getDeviceId = () => {};
export const getOSVersion = () => {};
export const exitApplication = () => {};
export const isTTSEnabled = () => {};
export const isLowEndDevice = () => {};
keyCodes
, since most platforms have keys on the remote dispatch onKeyDown
event with their own custom set of keyCodes
.if
or switch
is that code in modules for other platforms is never imported, and therefore shaken off by webpack at bundling time, reducing bundle size.<link rel="preload" as="font">
and avoiding flash of invisible text while fonts are loading by using font-display API, ie font-display: swap;
webp
format, and keep images as small as possible by loading in only what you need in terms of resolution. Ie, if user is on mobile, and image is displayed in ie 320x160, don't load huge image for desktop and resize it in-browser. This can be achieved by tools like Thumbor.<link rel="preconnect" href="https://example.com">
<link rel="dns-prefetch" href="https://example.com">
<link rel="prefetch" href="/bundle.js">
<link rel="preload" href="/something.chunk.js">
<script defer src="./script.js"></script>
<script async src="./script.js"></script>
const Library = React.lazy(() =>
import(
/* webpackChunkName: "library" */ /* webpackPrefetch: true */ './Components/Library/Library'
)
);
async componentDidMount() {
const genres = await fetchGenres();
this.setState({ genres });
const isPlatformReady = await platformReady();
if (isPlatformReady) {
this.setState({ isPlatformReady: true });
}
}
React.memo
There are two "schools of thought" here. First is use it all the time, second one is use it sparingly. If you decide to use it all the time, you might end up slightly improving performance for some components, having little to no impact on others, and having negative impact on edge cases. If you decide to evaluate and use it sparingly only where it makes sense, you'll be safer, but it does consume more time(which is one of the main arguments for "use it all the time" I've seen).
It sounds great in theory, but in practice it can easily prove "more trouble than it's worth". Eg. if a component has large number of props, might be the same or even faster to just let it re-render instead of making a costly check against all those props.
Personally, I'm leaning towards checking in the profiler whether you're getting something out of it.Context
is always somewhat costly to use.
Make sure it's not overused. Prop drilldown isn't ideal, but it might save you some performance hits of having every component ever connected to global state management.
One problem we encountered was with styled-components
a couple of years ago, when we started the project.
Not sure about now, but back then it used context for every single styled component.
Needless to say, we noticed performance hits, and quickly switched to good old sass.useMemo
and useCallback
are generally worth it, with some exceptions.
useMemo
is great for your stuff that is derived from props/state and useCallback
for your functions in components.
Main thing to watch out for here is using these if their dependencies change too often.
Ie, if you're memoizing function reference with useCallback
, but it's dependency is ie inputValue
which changes on every key press.
In that case, useCallback
just slows you down, as function reference will change anyway because of constantly changing dependency, you're just introducing memoization on top of recreating the function.