Skip to content

Instantly share code, notes, and snippets.

View vinayakhumberi's full-sized avatar
:octocat:

Vinayak Humberi vinayakhumberi

:octocat:
View GitHub Profile
jest.mock('react-redux', () => ({
connect: (mapStateToProps, mapDispatchToProps) => (reactComponent) => ({
mapStateToProps,
mapDispatchToProps: (dispatch = mockDispatch, ownProps) => mapDispatchToProps(dispatch, ownProps),
reactComponent,
mockDispatch: jest.fn((action) => action)
}),
Provider: ({children}) => children
}));
@vinayakhumberi
vinayakhumberi / Injecting scripts
Last active March 11, 2020 15:09
Performance Script usage
<script>
(function(d, script) {
script = d.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
// remote script has loaded
};
script.src = 'http://www.google-analytics.com/ga.js';
d.getElementsByTagName('head')[0].appendChild(script);
@vinayakhumberi
vinayakhumberi / XMLHttpRequest.js
Created March 11, 2020 15:01 — forked from CharlyJazz/XMLHttpRequest.js
XMLHttpRequest injection load javascript script.
//Before </body> tag
<script>
var xhr = new XMLHttpRequest();
xhr.open("get", "cookbook.js", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = xhr.responseText;
import Loadable from 'react-loadable';
export const ContactUs = Loadable({
loader: () => import('./source/pages/ContactUs/ContactUs'),
loading: () => LoadingPage
});
export const HomePage = Loadable({
loader: () => import('./source/pages/Home/HomePage'),
loading: () => LoadingPage
});
@vinayakhumberi
vinayakhumberi / react-lazy-suspense
Created March 11, 2020 10:36
React Lazy Suspense
import React, { Suspense } from 'react';
const OtherComponent = React.lazy(() => import('./OtherComponent'));
function MyComponent() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<OtherComponent />
</Suspense>
@vinayakhumberi
vinayakhumberi / webpack.config.js
Last active March 30, 2020 09:29
Webpack Performance 3
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
filename: '[name].bundle.[contenthash].js'
},
optimization: {
splitChunks: {
cacheGroups: {
@vinayakhumberi
vinayakhumberi / webpack.config.js
Last active March 30, 2020 09:31
Webpack Performance 2
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.[contenthash].js',
},
optimization: {
splitChunks: {
@vinayakhumberi
vinayakhumberi / webpack.config.js
Last active March 11, 2020 09:46
Webpack Performance Hacks
// Your default webpacl config
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main-webpack.bundle.js'
}
};
@vinayakhumberi
vinayakhumberi / index.html
Created August 14, 2019 05:53
Traffic distribution logic
<div>
<pre id="result"></pre>
</div>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals/>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>__YOUR_API_HOSTNAME_HERE__</HostName>
<ReplaceKeyPrefixWith>prod/resize?key=</ReplaceKeyPrefixWith>