MIME type của tệp .docx là gì?
MIME type (kiểu phương tiện) của tệp Microsoft Word có đuôi .docx là application/vnd.openxmlformats-officedocument.wordprocessingml.document. Đây là một kho lưu trữ ZIP chứa các tệp XML, nên bản thân nó đã được nén. Một số máy chủ cũ không nhận diện được kiểu này có thể trả về tệp DOCX với application/zip, khiến trình duyệt tải xuống dưới dạng .zip.
Content-Type header
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8
Các kiểu dựa trên văn bản nên kèm theo charset để trình duyệt giải mã ký tự chính xác.
Cấu hình máy chủ
| Máy chủ | Cấu hình |
|---|---|
Nginx (mime.types hoặc types {}) | application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; |
Apache (.htaccess) | AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx |
IIS (web.config) | <mimeMap fileExtension=".docx" mimeType="application/vnd.openxmlformats-officedocument.wordprocessingml.document" /> |
| Node.js / Express | res.type('docx') hoặc res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8') |
| Amazon S3 | Đặt Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document cho đối tượng (metadata), hoặc truyền --content-type application/vnd.openxmlformats-officedocument.wordprocessingml.document vào aws s3 cp |
Có nên nén tệp .docx không?
Không. Tệp Microsoft Word đã được nén sẵn bên trong, nên dùng gzip hoặc Brotli chỉ tốn CPU và hầu như không giảm dung lượng — thậm chí còn có thể làm tăng kích thước. Hãy loại application/vnd.openxmlformats-officedocument.wordprocessingml.document khỏi cấu hình nén của bạn.
Vì sao MIME type quan trọng
Trình duyệt quyết định sẽ làm gì với một phản hồi — hiển thị, thực thi, phát hay tải xuống — dựa trên header Content-Type, chứ không phải đuôi tệp. Với X-Content-Type-Options: nosniff, kiểu sai sẽ khiến stylesheet và script bị chặn hoàn toàn. Với tệp tải lên, đừng bao giờ tin vào kiểu do client gửi; hãy kiểm tra nội dung tệp (magic bytes) trên máy chủ.
Tra cứu MIME type
Tìm kiếm mọi đuôi tệp và MIME type phổ biến, kèm Content-Type header sẵn sàng sao chép.
Câu hỏi thường gặp
MIME type của .docx là gì?
application/vnd.openxmlformats-officedocument.wordprocessingml.document.Làm thế nào để đặt Content-Type cho .docx trong Nginx?
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx; có trong khối types (thường nằm ở /etc/nginx/mime.types), sau đó tải lại Nginx.