question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Magic Comments not working for images

See original GitHub issue

I am trying to preload/prefetch an image so that I don’t have to be connected to the internet at the exact moment to display the image. It’s for a “you are offline” page in my app.

I was reading online that the webpack magic comments feature might be able to do that. https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c

It’s not working for me.

Bug report

The image that I am trying to preload/prefetch does not show and there is no <link rel tag added to the DOM.

If the current behavior is a bug, please provide the steps to reproduce. Checkout the demo repository here: https://github.com/aubreyquinn/preload-webpack-demo/tree/main

What is the expected behavior? I should be able to pre-fetch an image and have the link rel tag added to my DOM.

Other relevant information:

  "devDependencies": {
    "@babel/core": "^7.19.6",
    "@babel/preset-env": "^7.19.4",
    "@babel/preset-react": "^7.18.6",
    "babel-loader": "^8.2.5",
    "css-loader": "^6.7.1",
    "file-loader": "^6.2.0",
    "html-webpack-plugin": "^5.5.0",
    "style-loader": "^3.3.1",
    "webpack": "^5.74.0",
    "webpack-cli": "^4.10.0",
    "webpack-dev-server": "^4.11.1"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Oct 21, 2022

It should be implemented by HtmlWebpackPlugin, webpack generate links only for JS assets

0reactions
alexander-akaitcommented, Oct 22, 2022

I asked @jantimon (https://github.com/jantimon/html-webpack-plugin/issues/1768#issuecomment-1270227968) to mvoe html-webpack-plugin to webpack-contrib to I will fix a lot of issues and implement such things

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack 5: magic comments not working for images
It's not working for me. The image that I am trying to preload/prefetch does not show and there is no <link rel tag...
Read more >
Webpack magic comments don't take effect. Images ... - GitHub
I have a component that has to switch between 4 images constantly, every time a property changes I import the specific image for...
Read more >
xetex - Magic comment doesn't seem to work in VScode? - TeX
One problem I encountered is that I need to write in Chinese and as such I need to specify the compiler as xelatex...
Read more >
Magic Comments - Tinkerwell
Magic comments are a powerful feature that came to Tinkerwell with version 3. They allow you to debug your code inline without changing...
Read more >
Fixing WebpackChunkName for Dynamic Imports - Time to Hack
Are the Webpack Magic Comments webpackChunkName not effective and working with Babel? See how to Fix it and Tips to avoid related problems....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found