I am developing a website using React and I use Webpack to bundle the files. I use several .png images on the site but I have a problem with one of these since when I try to create the package, this image is not loaded and in the Google Chrome console I read something like this:
GET http://localhost/bundle/data:image/png;base64,iVBOR...AAAAASUVORK5CYII= 414 (Request-URI Too Long)
This is my webpack.config.js
:
const webpackConfig = env => {
return {
mode: env === "development" ? "development" : "production",
entry: ["./src/index.tsx"],
output: {
filename: "bundle.js",
path: path.join(__dirname, "server/public/bundle/")
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
module: {
rules: [
{
test: /\.(jsx|tsx|js|ts)$/,
loader: "ts-loader",
options: {
transpileOnly: true,
compilerOptions: {
target: env === "development" ? "ES6" : "es5"
}
},
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader?limit=100000'
}
]
},
}
};
module.exports = env => webpackConfig(env);
By varying the limit used in url-loader?limit=100000
I noticed that under 30000 the image is displayed correctly but many other images do not work due an 404 errors.
How can I fix the problem?
There is no need to inline that much data as img src, just lower the limit of url-loader.
If you google a lil bit there is a lot about this issue, for example
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/414
How do I resolve a HTTP 414 "Request URI too long" error?
I know there is also problem with older browsers which won't accept long URIs so thats why there is that limit I think.
I suggest to lower your limit to max 10000