Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-05-14 05:39:31

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Serve static content from a cookieless sub-domain

I am experimenting to move all static content such as js, imgs, and files from a subdomain but txp serves me a warning as it does not recognise the images path, augmenting it instead on the main domain’s directory tree. I understand that this path is relative to the root of the site but is there a way to change it into a server path?

>Edited to add: Just discovered this relevant thread

>Edit 2: This is only for non txp managed content. Is there a way to have static.domain.tld/domain_name/images serve the images uploaded and generated by a txp install?

Last edited by colak (2018-05-14 06:07:11)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2018-05-14 07:38:18

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Serve static content from a cookieless sub-domain

Did you check wet and Phil’s tip with setting the static subdomain to use the same folder structure as your textpattern domain? Phil also describes it in a txptip. That should allow you use the txp admin area to save and manage images as before (the images stay where they are and don’t need moving) but to serve them as if from a separate subdomain.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2018-05-14 16:17:12

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Serve static content from a cookieless sub-domain

I’m researching how to create a symlink:)

I wish that images had a relative path… It would have been so much simpler.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2018-05-14 19:55:45

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Serve static content from a cookieless sub-domain

colak wrote #311750:

I’m researching how to create a symlink:)

I wish that images had a relative path… It would have been so much simpler.

If you can set your primary (sub)domain and your static domain to reference the same folder, then, from what I’ve understood, you don’t need the symlink at all, only the ihu line set in config.php.

If you’re dead set on using another folder tree for your static domain, you’ll need to set a symlink to make txp save not to its own images folder but to a parallel folder tree that you’re using for your static subdomain.

On your mac, it’s not a problem. Assuming you have two folders:

/path/to/your/maindomain/ --> assigned to www.yoursite.com
/path/to/your/subdomain/ --> assigned to static.yoursite.com
  • First make a copy of your current /images folder from your main domain in the folder tree of your static subdomain (perhaps take a backup while you’re at it for safety’s sake too).
  • Now you that you have copy, you can delete your /images folder in the main domain.
  • Open the Terminal.
  • Type cd{space} and then drag the Textpattern root folder (the one that until now contained your images folder) from the Finder into the terminal window and it will auto-fill the correct path. Press return.
  • Enter ln -s /path/to/your/maindomain/images /path/to/your/subdomain/images in the terminal, and press enter.
  • Your main domain will now have an entry called images with a small arrow next to it. If you double-click on it, you’ll see your images as before but now the path (if you have it switched on it shows at the bottom of the Finder) will be in the other folder tree.
  • Now add the ihu line to your config.php and you should be good to go.

As you can’t FTP symlinks, if you want to do this on your public server, you need to create the symlink on your host. If you have shell access (an SSH login), you can use your ssh login details to log in to your host via the terminal, then cd /folder/subfolder/subfolder your way to the correct folder on your host. Then run the ln -s … as above (with the server paths) to create the symlink.

If you don’t have shell access, you need to see if your host’s control panel provides a way of creating a symlink. With my host, I have to use the host’s web ftp navigator tool and “create symlink” is an item in its context menu. Your host may be different.

Good luck!


TXP Builders – finely-crafted code, design and txp

Offline

#5 2018-05-15 05:43:18

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: Serve static content from a cookieless sub-domain

What I was hoping for was to centralise the images and files from a site and its subdomains on a particular subdomain as it will be much easier to back up but it seems this is not possible…


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2018-05-15 06:58:40

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,595
Website

Re: Serve static content from a cookieless sub-domain

You might be able to do that with your symlinking approach, but I suggest you try it out first. The symlink syntax is:

ln  -s  symlink-name  link-destination

The link destination can be relative if you prefer, and if you are already in the correct directory in the terminal, you don’t actually need to specify the entire source path (unlike what I wrote above).

So, you could feasibly set up a static domain like this:

/staticdomain
   /website-a
      /assets
      /files
      /images
   /website-b
      /assets
      /files
      /images
…

Then in the respective root folders of your subdomains set the symlinks so that the respective images, assets and files symlinks point to the respective equivalent folder in your static domain. You’ll need to then adjust your ihu line in each config.php to point to:

define('ihu', 'http://static.domain.com/website-a/');

or website-b, and so on.

I don’t think txp’s file_download links use ihu, so you may need to manually construct your file links instead. The same goes for your asset links (js, css, webfonts, icons, ui images) if you’re using them.

You can, of course, use another folder structure or split the asset links and the image links into separate static subdomains as Phil has suggested.


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB