Code Monkey home page Code Monkey logo

Comments (3)

theKashey avatar theKashey commented on June 17, 2024

Your solution for server-side definitely works, but I am not sure if it can be adapted for client side.

The problem is - loadable is not importing scripts by itself, it's just asking webpack to do so with all script names being hardcoded in the webpack manifest.

So you have the following options:

  • (hard) modify your script by injecting the language to alter manifest file and point to other files
  • (easy) change URL format to /en-US/some/component/chunks.js, in this case you can use webpack.publicPath to control "prefix" setting it to where it should
    • done, that works like magic and more importantly scripts dont use any query string and are better cacheable

from loadable-components.

Hacksign avatar Hacksign commented on June 17, 2024

Solution I currently use is adding a routing method, which is by cookie, in nginx proxy server.

Then add response.cookie('lang', language) in request handler (which is server_side_renderer function in my project), so when the first request is responsed, there will be a lang field in the continuing request in HTTP Cookie header.

(⬆️ The hard way)

The easy way, is not that easy actually, because sometimes there may be dynamic language support demand, this is why I said:

NOTE: dynamic loaded component should stick to this rule as well.

As there is dynamic demands, webpack.publicPath is not a perfect solution as well, this can only solve static situations. There will be multi entry scripts which is compiled with different webpack.publicPath, the only difference among these scripts is the webpack.publicPath.

Maybe loadable's webpack plugin can add some hooks to solve this ? I'm not familiar with webpack development (actually I'm not a frontend engineer...).

from loadable-components.

theKashey avatar theKashey commented on June 17, 2024

Then add response.cookie('lang', language) in request handler

That actually should work out of the box. Just use cookies not extra query parameters

As there is dynamic demands, webpack.publicPath is not a perfect solution as well,

It is, because it can be configured in runtime. And that would be same script, just prefixed with language - something nginx can use instead of query attribute.

Maybe loadable's webpack plugin can add some hooks to solve this

It cannot because it's not only about loadable-stats (server side), but client-side as well, fully managed by webpack

from loadable-components.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.