3 ms·
When is this every useful?
by jonny_eh 8y ago
When is this every useful?
- eridius 8y agoIt's useful if you're developing a static HTML page, loading it from your local filesystem via a file:// URL but want it to pretend like it's at the expected http:// http:// URL. Of course, you wouldn't ever publish it like this. I'm unsure if there's any utility to publishing a publicly-visible page using this tag.
- matmo 8y agoIf you use a CI system that deploys each build of your webapp, where it might be deployed at a random url (<domain>/build1/index.html vs. <domain>/build2/index.html), then you would make all the url's in your app relative urls, which are then basically prefixed by the base url specified in the document head once the actual requests get sent. You can then write a different base href onto the document for each build, and everything will magically work. Also, if ever use relative urls for assets or requests, and you deploy to different URL's (or your deployed URL path's don't map 1:1 to your filesystem paths), it can come in handy. Angular also uses this to determine where the client side routing begins - https://angular.io/guide/deployment#base-tag https://angular.io/guide/deployment#base-tag .
- kccqzy 8y agoWe have a system where all of our static assets are prefixed with the SHA1 of the git commit that produces them. It's a great cache-busting technique for CDNs. But this also means we cannot use paths like /img/background.jpg but rather /<insert 40 hex chars here>/img/background.jpg when we refer to such assets. Of course most of the time we can compute this by JavaScript on the client side but it's often easier just to use <base> and get rid of that piece of JavaScript. Another use class is to change all links to open in a new tab by setting only "target" on the <base>. This happens on marketing sites with a lot of third party links so the marketing department naturally wants those links to open in a new tab instead of the current tab.
- ldjb 8y agoSome websites do use <base target="_blank"> to make links open in a new tab by default. However, this can create a vulnerability as the linked website now has a reference to your site through window.opener and can take the user away from your site: https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/ https://www.jitbit.com/alexblog/256-targetblank---the-most-u...
- chias 8y agoIt's pretty useful when making phishing pages. Rather than having to host all the tiny files and images yourself or going through what is likely an enormous HTML file and editing all the srces and hrefs, you can just throw a <base> tag on there and be done with it. Admittedly this is probably not the use case you're looking for.