QueraTeam / django-nextjs

Next.js integration for Django projects
MIT License
341 stars 17 forks source link

Request for compression support in django-nextjs #14

Closed sebherrerabe closed 1 year ago

sebherrerabe commented 1 year ago

I have been using the django-nextjs library for my project and it has been a great help so far. However, I noticed that when I access the Next.js application directly on http://localhost:3000/ the JavaScript files are compressed with content-encoding gzip, but when I access the Django server (which is redirecting the files from Next.js), the files are no longer compressed.

I understand that the library does not currently support compression and I apologize if my request is an inconvenience. I have tried using the built-in GZipMiddleware in Django, but it did not work. I also tried using a reverse proxy like Nginx or Apache in front of my Django server, but it still doesn't work.

I would greatly appreciate it if compression support could be added to the django-nextjs library. This would make it easier for users like me to deliver compressed files to the client, improving performance and reducing bandwidth usage.

Thank you for your time and effort in maintaining this library, it has been a great help to me. Please let me know if you need any more information or if you have any questions.

mjnaderi commented 1 year ago

I'm glad that this package has been helpful to you.

Static assets should be served (proxied) by django server only in local development environment.

In production, as stated in README, you need to serve /_next/static/... (all JavaScript files and other static assets) using a web server like Nginx. You can configure Nginx and enable gzip compression.

gzip on;
gzip_comp_level 2;
gzip_proxied any;
# Don't compress anything that's already small and unlikely to shrink much if at all
# The default is 20 bytes, which is bad as that usually leads to larger files after gzipping
gzip_min_length 1000;  # 1000 bytes
gzip_types
    text/plain
    text/html
    text/css
    text/javascript
    application/x-javascript
    application/javascript
    application/json
    text/xml
    application/xml
    application/rss+xml
    application/atom+xml
    application/xhtml+xml
    image/svg+xml;