<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Lazic on Medium]]></title>
        <description><![CDATA[Stories by David Lazic on Medium]]></description>
        <link>https://medium.com/@dlazic?source=rss-77643f0e68a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*77wkdB4jvjOL2076hf5Hrw.png</url>
            <title>Stories by David Lazic on Medium</title>
            <link>https://medium.com/@dlazic?source=rss-77643f0e68a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 18:36:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dlazic/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[KRACKing the WPA2]]></title>
            <link>https://medium.com/@dlazic/kracking-the-wpa2-2898e8d14211?source=rss-77643f0e68a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2898e8d14211</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[krack]]></category>
            <category><![CDATA[wpa2]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[David Lazic]]></dc:creator>
            <pubDate>Wed, 18 Oct 2017 16:34:28 GMT</pubDate>
            <atom:updated>2017-10-18T18:50:15.724Z</atom:updated>
            <content:encoded><![CDATA[<p>Expoit summary</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*Dn2NQUsNbXYeNu_-I4IwDg.jpeg" /></figure><p>A couple of days ago we got news that a security flaw was discovered in WiFi Protected Access II (<a href="https://en.wikipedia.org/wiki/IEEE_802.11i-2004">WPA2</a>). Considering that WPA2 is around 14 years old, it’s a wonder that the flaw hadn’t been found earlier. As most of us use some kind of WiFi today, I think it’s important for people who don’t specialize in this area to gain a basic insight of what’s going on. So here I’ll try to present a summary report of the exploit.</p><p>The attack is called KRACK (Key Reinstallation Attack) and uses a Man in the Middle (MitM) attack methodology. It happens during the 4-way handshake phase and revolves around client using an all-zero key to encrypt communication with an Access Point (AP).</p><h3><strong>How does it work?</strong></h3><p>Most of the news spin around the title <strong>CRACKED</strong>, even though the vulnerability isn’t in the protocol itself, but in its implementation. WPA2 protocol is mathematically proven to be secure, it describes <strong>how </strong>parties should establish a secure connection, but not <strong>when</strong>. KRACK exploits this by intercepting responses at a particular<strong> point in time</strong> resulting in a predictable behavior from both parties.</p><p>There are couple of requirements which need to be met in order for the attack to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/0*9fBo2dtmHHDkfgOn." /></figure><h4><strong>Rogue channel</strong></h4><p>C needs to create an AP rogue channel in order to sniff data packets in A — &gt; B communication.<br>This way C impersonates B only on a different broadcasting channel. <br>C can see data packets being transmitted, although they will be encrypted.<br>The danger here is that C doesn’t need to be connected to any network at all, so he doesn’t need to know B’s password.</p><h4><strong>4-way handshake</strong></h4><p>In order to establish a connection, A and B need to perform a 4 way handshake. This means that the initial communication will consist of 4 messages between A and B through which they will prove to each other that both know the Pairwise Master Key (PMK) generated out of the network’s (B’s) passphrase without even disclosing the key. This assures that rogue AP channels (above) won’t be able to decrypt data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*ri7DRXT9rXItcZ2x." /></figure><p>The first 2 communication steps revolve around assuring that the PMK is known from both parties. B will encrypt a message with PMK and forward encrypted message with its current nonce to A. A will decrypt the message with its PMK, increment its nonce, encrypt message again and send response to B. If this communication is consistent they jump into <em>critical</em> step 3 where KRACK is possible.</p><p>At step 3, B will generate a Pairwise Transient Key (PTK) out of:<br>- PMK<br>- A nonce and MAC address<br>- B nonce and MAC address</p><p>B will send PTK to A, which will install it, increment its current nonce and respond to B so they can end the handshake.</p><p>But what happens if B nevers gets A’s response about the installed key?<br>B will resend the PTK to A which will repeat the key installment and nonce increment process. This will result in A resetting its nonce and replay counter and install the already used PTK. At that point we can stop interrupting A’s response, which B will confirm and the handshake is ended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*RM_crklyAFCz0oi4." /></figure><p>In each of the communication steps they send each other incremental <a href="https://en.wikipedia.org/wiki/Cryptographic_nonce">nonces</a> (number to be used only once). By combining current nonce with the key, they are able to generate a series of 0s and 1s which is called a keystream. By XOR-ing keystream and plaintext data ciphers encrypt messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*s3eRTSrLFG0wgEBP." /></figure><p>Since A installed all-zero PTK it is possible to decrypt some, if not all of the data packets through decryption methods such as <a href="http://travisdazell.blogspot.rs/2012/11/many-time-pad-attack-crib-drag.html">crib dragging</a>.</p><p>The KRACK exploit not only enables us to decrypt the traffic, but depending on the initial setup it can lead to forging and even injecting data frames sent to the client.</p><p>Official video presentation showcases use of a rogue AP channel, running a KRACK attack with all-zero key installation, <a href="https://moxie.org/software/sslstrip/">SSL strip</a> method and displaying the plaintext data.</p><h4><strong>Links</strong></h4><p>* <strong>Official website disclosing the vulnerability</strong><br><a href="https://www.krackattacks.com/">https://www.krackattacks.com<br></a>* <strong>Detailed mechanism</strong><br><a href="https://papers.mathyvanhoef.com/ccs2017.pdf">https://papers.mathyvanhoef.com/ccs2017.pdf<br></a>* <strong>Current patch status</strong><br><a href="https://char.gd/blog/2017/wifi-has-been-broken-heres-the-companies-that-have-already-fixed-it">https://char.gd/blog/2017/wifi-has-been-broken-heres-the-companies-that-have-already-fixed-it</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2898e8d14211" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React + Firebase — Persistent Auth]]></title>
            <link>https://medium.com/netscape/react-firebase-persistent-auth-e69ad99b7722?source=rss-77643f0e68a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e69ad99b7722</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[David Lazic]]></dc:creator>
            <pubDate>Fri, 06 Oct 2017 23:57:03 GMT</pubDate>
            <atom:updated>2017-10-06T23:59:57.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PR3klDbot3ZS9Kp69LYtHA.png" /></figure><p>Lately I’ve been playing around with Firebase and so far — I like it. It’s got its own quirks, but nothing unbearable. It’s analogous to the MEAN stack, except that with Firebase we have a real time API based on a WebSocket protocol out of the box.</p><p>One of the peculiar things of building an app based on a WebSocket approach is the persistent Auth implementation. <br>Personally, I’m used to working with stateless, REST based APIs which have a <em>ping</em> method that you can call from the app. The app would send <strong>http</strong> <strong>GET</strong> request with a bearer token — &gt; if the token is valid we would retrieve currently logged in user or receive invalid token error.</p><p>With Firebase, there is no such thing as a <em>ping</em> request. Here we need to have a reactive, event based system implemented by setting an observer on Firebase’s auth.</p><p>So, let’s demonstrate a simple view routing system with public / protected routes.</p><blockquote>Notice that snippets are based on React Router v3, but the similar approach can be applied to v4.</blockquote><pre>&lt;Route path={ publicPath } component={ App } &gt;<br>  &lt;IndexRoute component={ Home } /&gt;<br>  &lt;Route path={ routeCodes.LOGIN } component={ Login } /&gt;<br>  &lt;Route path={ routeCodes.ADMIN } component={ Admin } /&gt;<br>&lt;/Route&gt;</pre><p>We have an App component acting as a wrapper for all the child routes. Initial render would present us a Home component, Login route will serve as our public route and we want to restrict access to Admin route if user isn’t logged in.</p><p>When we browse our public (“/login”) route we can present our “smart” Login view which implements <strong>onLogin</strong> method for a user to sign in to the Firebase.</p><pre>onLogin ({ email, password }) {<br>  firebase.auth().signInWithEmailAndPassword(email, password))<br>    .then(() =&gt; browserHistory.push(routeCodes.ADMIN))</pre><p>If Firebase responds with a success, we redirect our user to the Admin route — simple enough.</p><p>So how do we protect the Admin route?</p><p>One approach is to use Routes’ <strong>onEnter </strong>method and do a check of a current user in Firebase via <em>firebase.auth().currentUser.</em> But here’s the kicker — we <strong>can’t</strong> use this approach in case of a browser refresh directly on a protected route (“/admin”) as there’s no guarantee that Firebase package will be instantiated at that point, so most of the times <em>currentUser</em> will be <em>null.<br></em>This is the question that’s been repeatedly asked throughout the web.</p><p>The other approach is to create an <em>AuthResolver </em>wrapper component, which in our case can be the App component itself.</p><pre>firebase.auth().onAuthStateChanged(user =&gt; this.setState({ user }));</pre><p>When our resolver mounts, we set an observer to Firebase’s <em>auth</em>, and we store the observer’s response inside the state, whatever the user might be — user <strong>object</strong> or <strong>null.</strong></p><p>Since <em>setState</em> triggers <em>componentWillUpdate</em> method we can do our protected route check there and immediately do a redirection in case user isn’t logged in. Otherwise, we’ll let React render the requested route.</p><pre>componentWillUpdate (props, state) {<br>  if (!this.isAuthorized(props.children.props.route.protected, state.user)) {<br>    browserHistory.push(routeCodes.ROOT);<br>  }<br>}</pre><p>What’s left is to add <strong>protected </strong>flag onto each route we want to restrict access to.</p><pre>&lt;Route path={ routeCodes.ADMIN } component={ Admin } <strong>protected</strong> /&gt;</pre><p>This approach ensures we have a single entry point for the Auth check which is easy to scale up in a more complicated case of different protected states.<br>It somewhat reminds me of writing an attribute directive back in Angular 1x which is neat.</p><p>Here are the full gists:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e67e7556845adca34d04889a2778a86/href">https://medium.com/media/1e67e7556845adca34d04889a2778a86/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a91ee4037b91ba86c0ae9228232537a/href">https://medium.com/media/8a91ee4037b91ba86c0ae9228232537a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7340dae9a8c00a7f16ecc2cc18112a60/href">https://medium.com/media/7340dae9a8c00a7f16ecc2cc18112a60/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e69ad99b7722" width="1" height="1" alt=""><hr><p><a href="https://medium.com/netscape/react-firebase-persistent-auth-e69ad99b7722">React + Firebase — Persistent Auth</a> was originally published in <a href="https://medium.com/netscape">Netscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack 3 + React — Production build tips]]></title>
            <link>https://medium.com/netscape/webpack-3-react-production-build-tips-d20507dba99a?source=rss-77643f0e68a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d20507dba99a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[David Lazic]]></dc:creator>
            <pubDate>Thu, 06 Jul 2017 11:02:12 GMT</pubDate>
            <atom:updated>2018-04-03T22:29:09.102Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpP4es42Jdv-Ikmd4M4xWw.jpeg" /></figure><p>Couple of days ago I had the honor to upgrade our project’s Webpack build as we strived to polish the app’s performance. Squeezing the maximum out of Webpack’s build definitely gave us significant improvements.</p><p>Here I will try to share some guidelines that could help you understand your Webpack’s configuration better and figure out a way to get the optimal setup for the project you’re working on.</p><blockquote>Notice:</blockquote><blockquote>I’ve only shown parts of the code in examples below, but be wary that the plugins’ configuration order can be crucial for some of them.</blockquote><blockquote>Full gist is included at the bottom of this article.</blockquote><h4>Migrate Webpack version</h4><p>If you’re still deciding whether to upgrade your Webpack 1, I’d say — <strong>definitely go for the upgrade</strong>. <em>v1 → v2</em> could be a bit of a hassle, but <em>v2 → v3</em> is in 98% of the cases smooth (<a href="https://medium.com/webpack/webpack-3-official-release-15fd2dd8f07b">per Webpack’s team statistics</a>).</p><p>Migration alone will boost bundles’ performance and reduce their size significantly. We’ll obtain <a href="https://webpack.js.org/guides/tree-shaking/"><strong>tree shaking</strong></a> feature in v2 and <a href="https://medium.com/webpack/brief-introduction-to-scope-hoisting-in-webpack-8435084c171f"><strong>scope hoisting</strong></a> in v3. First one comes as a built-in feature starting from v2, but scope hoisting needs to be enabled in v3 by using <em>ModuleConcatenationPlugin.</em></p><pre>plugins: [<br>  new webpack.optimize.ModuleConcatenationPlugin()<br>]</pre><h4>Code splitting &amp; cashing</h4><p>Instead of ending up with one huge <em>bundle.js</em>, we can <a href="https://webpack.js.org/guides/code-splitting/"><strong>split</strong></a> our app and vendor code into separate files.</p><p>We can do that by defining an entry point for our app code and then using a <em>CommonsChunkPlugin</em> to bundle everything from <em>node_modules</em> into vendor.</p><p>We’ll also add cache busting via <a href="https://webpack.js.org/guides/caching/"><strong>chunkhash</strong></a> so that all of the output files have different hashes. Each files’ hash will stay the same with each build unless its file contents have changed.</p><pre>entry: {<br>  app: path.resolve(sourcePath, &#39;index.js&#39;)<br>},<br>output: {<br>  path: path.join(__dirname, &#39;dist&#39;),<br>  filename: &#39;[name].[chunkhash].js&#39;,<br>  publicPath: &#39;/&#39;<br>},<br>plugins: [<br>  new webpack.optimize.CommonsChunkPlugin({<br>    name: &#39;vendor&#39;,<br>    filename: &#39;vendor.[chunkhash].js&#39;,<br>    minChunks (module) {<br>      return module.context &amp;&amp;<br>             module.context.indexOf(&#39;node_modules&#39;) &gt;= 0;<br>    }<br>  })<br>]</pre><h4>Dynamic import &amp; lazy-loading?</h4><p>This type of optimization is still a debatable one. There are many factors to consider and a couple of different ways to achieve this, but eventually it really comes down to project’s characteristics.</p><p><em>Webpack 2</em> comes with an improvement regarding <a href="https://webpack.js.org/guides/code-splitting/"><strong>dynamic imports</strong></a><em>. </em>While the legacy way was using <em>require.ensure</em>, latest release follows the <a href="https://github.com/tc39/proposal-dynamic-import"><strong>TC39 standards proposal</strong></a> and uses the <em>import()</em> syntax.</p><p>On the other hand, <em>react-router 4</em> came with improvements to <a href="https://reacttraining.com/react-router/web/guides/code-splitting"><strong>lazy-load</strong></a> your components by using <a href="https://github.com/webpack-contrib/bundle-loader"><strong>bundle-loader</strong></a>.</p><p>I haven’t had the time to test this in depth, but the things I’ve tried didn’t have much of an impact. You could even say that they degraded the performance on the project I’ve been working on.</p><h4><strong>Minification</strong></h4><p>Minifying Webpack’s output is really important in order to reduce its size.</p><p><a href="https://github.com/jantimon/html-webpack-plugin"><strong>html-webpack-plugin</strong></a> is a great tool for compiling <em>.html</em> files. We can use one of the templating engines (.hbs|.ejs) for the index file, which will be compiled to index.html.</p><pre>const HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);</pre><pre>plugins: [<br>  new HtmlWebpackPlugin({<br>    template: path.join(__dirname, &#39;index.ejs&#39;),<br>    path: buildPath,<br>    excludeChunks: [&#39;base&#39;],<br>    filename: &#39;index.html&#39;,<br>    minify: {<br>      collapseWhitespace: true,<br>      collapseInlineTagWhitespace: true,<br>      removeComments: true,<br>      removeRedundantAttributes: true<br>    }<br>  })<br>]</pre><p>Minification of the <em>.js</em> output starts with built-in <em>UglifyJsPlugin</em>. Uglify’s compression config below is suggested by many tutorials online as one of the best for production builds.</p><p>There’s also an option to use identifiers instead of module names to minize the output a bit more. To enable this simply invoke <em>HashedModuleIdsPlugin </em>(<em>NamedModulesPlugin </em>is recommended for development)<em>.</em></p><pre>plugins: [<br>  new webpack.optimize.UglifyJsPlugin({<br>    compress: {<br>      warnings: false,<br>      screw_ie8: true,<br>      conditionals: true,<br>      unused: true,<br>      comparisons: true,<br>      sequences: true,<br>      dead_code: true,<br>      evaluate: true,<br>      if_return: true,<br>      join_vars: true<br>    },<br>    output: {<br>      comments: false<br>    }<br>  }),<br>  new webpack.HashedModuleIdsPlugin()<br>]</pre><p>We can further reduce the size of React’s vendor by using <a href="https://facebook.github.io/react/docs/optimizing-performance.html"><strong>production NODE_ENV</strong></a> setting, which would remove all the development oriented warnings and overhead.</p><pre>plugins: [<br>  new webpack.DefinePlugin({<br>    &#39;process.env.NODE_ENV&#39;: JSON.stringify(&#39;production&#39;)<br>  })<br>]</pre><h4>Internalize critical CSS</h4><p>When a user’s connection is slow, we want the first paint to be as fast as possible, so the general idea is to identify critical, visual parts of the project and internalize their CSS directly on the page (e.g. general layout, header &amp; footer, fonts). That way we’ll be able to provide perceptually faster load time.</p><p>We can simply split SCSS modules into <em>base.scss</em> and <em>style.scss</em>,<em> </em>where base would contain all those critical parts.</p><p>First step is to <a href="https://github.com/webpack-contrib/extract-text-webpack-plugin"><strong>extract</strong></a><strong> </strong>and minify all the CSS from webpack’s entry points as separate files. After that we run through the chunks and <a href="https://github.com/numical/style-ext-html-webpack-plugin"><strong>internalize</strong></a> critical ones inside the head section of the compiled index.html.</p><pre>const ExtractTextPlugin = require(&#39;extract-text-webpack-plugin&#39;);<br>const StyleExtHtmlWebpackPlugin = require(&#39;style-ext-html-webpack-plugin&#39;);</pre><pre>plugins: [<br>  new ExtractTextPlugin({<br>    filename: &#39;[name].[contenthash].css&#39;,<br>    allChunks: true<br>  }),<br>  new StyleExtHtmlWebpackPlugin({<br>    minify: true<br>  })<br>]</pre><h4>Source maps</h4><p>By choosing source map style we can further reduce the size of the build. Webpack’s <a href="https://webpack.js.org/configuration/devtool/"><strong>devtools</strong></a> option enables you to set the appropriate style.</p><p>There are multiple style options, but generally most of the online guides suggest using <em>cheap-module-source-map </em>option for development, and <em>source-map</em> in production.</p><p><em>Note: Corrected devtools mode, thanks </em><a href="https://medium.com/u/3cdddc4169a9"><em>David Patrick!</em></a></p><pre>devtool: &#39;source-map&#39;</pre><h4><strong>Async and defer</strong></h4><p>Setting one of these modes onto script tags will modify their loading order and can consequently lead to faster page load time as you’ll avoid render-blocking requests. Identify and separate the code that needs to be executed immediately from the code that could be executed later on.</p><p>With <a href="https://github.com/numical/script-ext-html-webpack-plugin"><strong>script-ext-html-webpack-plugin</strong></a> we can set different script options for compiling.</p><pre>const ScriptExtHtmlWebpackPlugin = require(&#39;script-ext-html-webpack-plugin&#39;);</pre><pre>plugins: [<br>  new ScriptExtHtmlWebpackPlugin({<br>    defaultAttribute: &#39;defer&#39;<br>  })<br>]</pre><blockquote>Warning: Async and defer attributes are essentially different in their execution time. Both types will load in parallel with HTML parsing. The difference is that <strong>async</strong> scripts will <strong>execute immediately</strong> after their load is complete, while <strong>deferred</strong> scripts <strong>will wait</strong> for the HTML parsing to be complete and will be executed in their respective order.</blockquote><h4><strong>Dns-prefetch and preload</strong></h4><p>Consider using <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control"><strong>dns-prefetch</strong></a> links for certain domains if you need to use 3rd party code. This will ensure that the browser does DNS lookup before the asset is requested later on.</p><pre>&lt;link rel=&quot;dns-prefetch&quot; href=&quot;<a href="https://www.google.com/">https://www.&lt;example_domain&gt;.com</a>&quot;&gt;</pre><p><a href="https://w3c.github.io/preload/"><strong>Preloading</strong></a><strong> </strong>will<strong> </strong>initiate<em> early, high-priority, and non-render-blocking</em> fetch of a resource which will be used later on. To add these at compile time, we can use <a href="https://github.com/GoogleChrome/preload-webpack-plugin"><strong>preload-webpack-plugin</strong></a><strong>.</strong></p><pre>const PreloadWebpackPlugin = require(&#39;preload-webpack-plugin&#39;);</pre><pre>plugins: [<br>  new PreloadWebpackPlugin({<br>    rel: &#39;preload&#39;,<br>    as: &#39;script&#39;,<br>    include: &#39;all&#39;,<br>    fileBlacklist: [/\.(css|map)$/, /base?.+/]<br>  })<br>]</pre><h4>Enable gzip compression</h4><p><a href="https://github.com/webpack-contrib/compression-webpack-plugin"><strong>Gzipping</strong></a> build files will reduce their size by a huge amount. In order for this to work we’ll also need to do modifications on your webserver config (e.g. Apache|Nginx). If the browser supports gzip that’s what he’ll receive.</p><pre>const CompressionPlugin = require(&#39;compression-webpack-plugin&#39;);</pre><pre>plugins: [<br>  new CompressionPlugin({<br>  asset: &#39;[path].gz[query]&#39;,<br>  algorithm: &#39;gzip&#39;,<br>  test: /\.js$|\.css$|\.html$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,<br>  threshold: 10240,<br>  minRatio: 0.8<br>  })<br>]</pre><h4>Service worker</h4><p>Consider using a service worker to cache your build files (all or some), if needed. There are some really great plugins that do this out of the box, such as <a href="https://github.com/NekR/offline-plugin"><strong>offline-plugin</strong></a> or <a href="https://github.com/goldhand/sw-precache-webpack-plugin"><strong>sw-precache-webpack-plugin</strong>,</a> or you can write your own service worker.</p><p>This is how the end configuration file looked like.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26537ef7df962ed755196e4ff9bb0b2c/href">https://medium.com/media/26537ef7df962ed755196e4ff9bb0b2c/href</a></iframe><h4>Results</h4><p>I’ll add screenshots of the app’s load times in development and production environment with good 3G network throttling.</p><blockquote>Notice that there’s some overhead included because of the loaded fonts and images, but that optimization topic is too wide for this article.</blockquote><p>First case is development build. As shown below, <em>app.js</em> is enormous in size as we’ve bundled up everything with no optimizations<em>.</em></p><pre>app.83852f151d1eccbe4a08.js         2.63 MB<br>app.83852f151d1eccbe4a08.js.map     3.08 MB      <br>index.html                          1.31 kB</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*kGBk0vJb13zUCH5ZGf7_yg.png" /><figcaption>Environment: DEVELOPMENT</figcaption></figure><p>When we apply build optimizations we end up with split app and vendor files, main css file and base css which was injected directly inside index.html.</p><p>We reduced the size alone more than <strong>89% </strong>and managed to improve load time more than <strong>74%</strong>!</p><pre>app.6c682e3a87517dd36425.js.gz                  21.9 kB<br>app.a5a5d15f6b07d45545a0794a327ab904.css.gz     30.9 kB<br>vendor.68f62e37ce5bcaf5df30.js.gz               220 kB<br>index.html                                      13.7 kB</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*_s6gE5ln4irObZ6nsdqriQ.png" /><figcaption>Environment: PRODUCTION</figcaption></figure><h4>Conclusion</h4><p>It’s definitely worth upgrading and optimizing your Webpack configuration, especially if you want to build performant apps. You’ll see an improvement from version upgrade alone (we gained around 4 to 5 sec faster load time, <em>v1 — &gt; v3</em>).</p><p>Lastly, I hope this article will help you achieve a bit more understanding of what are the general guidelines of improving your build and app’s performance with Webpack.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d20507dba99a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/netscape/webpack-3-react-production-build-tips-d20507dba99a">Webpack 3 + React — Production build tips</a> was originally published in <a href="https://medium.com/netscape">Netscape</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>